return 0;
}
+static char *__get_external_image_path_by_handle(pkgmgrinfo_pkginfo_h handle)
+{
+ int ret;
+ char *result_path;
+
+ ret = pkgmgrinfo_pkginfo_get_external_image_path(handle, &result_path);
+ if (ret != PMINFO_R_OK)
+ return NULL;
+
+ return strdup(result_path);
+}
+
+static char *__get_external_image_path_by_pkgid(const char *pkgid)
+{
+ int ret;
+ char *result_path;
+ pkgmgrinfo_pkginfo_h handle;
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret != PMINFO_R_OK)
+ return NULL;
+
+ result_path = __get_external_image_path_by_handle(handle);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+ return result_path;
+}
+
static long long __calculate_directory_size(int dfd, bool include_itself)
{
long long size = 0;
return -1;
}
-static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir,
+static int __calculate_shared_dir_size(int dfd, const char *app_root_dir,
long long *data_size, long long *app_size,
long long *cache_size)
{
subfd = openat(fd, "data", O_RDONLY | O_DIRECTORY);
if (subfd >= 0) {
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* shared/data directory */
size = __calculate_directory_size(subfd, false);
if (size < 0) {
LOGE("Calculating shared/data directory failed.");
subfd = openat(fd, "trusted", O_RDONLY | O_DIRECTORY);
if (subfd >= 0) {
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* shared/trusted directory */
size = __calculate_directory_size(subfd, false);
if (size < 0) {
LOGE("Calculating shared/trusted directory failed.");
subfd = openat(fd, "cache", O_RDONLY | O_DIRECTORY);
if (subfd >= 0) {
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* shared/cache directory */
size = __calculate_directory_size(subfd, false);
if (size < 0) {
LOGE("Calculating shared/cache directory failed.");
return -1;
}
-static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid,
+static int __calculate_pkg_size_info(STORAGE_TYPE type,
+ const char *pkgid, const char *ext_image_path,
long long *data_size, long long *cache_size,
long long *app_size)
{
tzplatform_mkpath3(TZ_USER_NAME, "apps_rw", pkgid));
free(sdpath);
tzplatform_reset_user();
+ if (ext_image_path) {
+ subfd = open(ext_image_path, O_RDONLY);
+ if (subfd < 0) {
+ LOGE("open() failed, path: %s, errno: %d (%s)",
+ ext_image_path, errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ } else {
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, path: %s, "
+ "errno: %d (%s)",
+ ext_image_path, errno,
+ strerror_r(errno, buf,
+ sizeof(buf)));
+ close(subfd);
+ return -1;
+ }
+ /* external image file */
+ *app_size += __stat_size(&st);
+ close(subfd);
+ }
+ }
} else {
LOGE("Invalid STORAGE_TYPE");
return -1;
}
if (strncmp(name, "data", strlen("data")) == 0) {
LOGD("traverse path: %s/%s", app_root_dir, name);
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* data directory */
size = __calculate_directory_size(subfd, false);
if (size < 0) {
LOGE("Calculating data directory failed.");
LOGD("data_size: %lld", *data_size);
} else if (strncmp(name, "cache", strlen("cache")) == 0) {
LOGD("traverse path: %s/%s", app_root_dir, name);
+ ret = fstat(subfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ *app_size += __stat_size(&st); /* cache directory */
size = __calculate_directory_size(subfd, false);
if (size < 0) {
LOGE("Calculating cache directory failed.");
*cache_size += size;
LOGD("cache_size: %lld", *cache_size);
} else if (strncmp(name, "shared", strlen("shared")) == 0) {
- size = __calculate_shared_dir_size(dfd, app_root_dir,
+ ret = __calculate_shared_dir_size(dfd, app_root_dir,
data_size, app_size, cache_size);
- if (size < 0) {
+ if (ret < 0) {
LOGE("Calculating shared directory failed.");
goto error;
}
- *app_size += size;
LOGD("app_size: %lld", *app_size);
} else {
LOGD("traverse path: %s/%s", app_root_dir, name);
return size_info_str;
}
-static int __get_pkg_size_info(const char *pkgid,
+static int __get_pkg_size_info(const char *pkgid, const char *ext_image_path,
pkg_size_info_t *pkg_size_info)
{
int ret;
ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL_GLOBAL_PATH,
- pkgid, &pkg_size_info->data_size,
+ pkgid, ext_image_path, &pkg_size_info->data_size,
&pkg_size_info->cache_size, &pkg_size_info->app_size);
if (ret < 0) {
LOGE("failed to calculate interal(global) size " \
}
ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL_USER_PATH,
- pkgid, &pkg_size_info->data_size,
+ pkgid, ext_image_path, &pkg_size_info->data_size,
&pkg_size_info->cache_size, &pkg_size_info->app_size);
if (ret < 0) {
LOGE("failed to calculate interal(user) size " \
}
ret = __calculate_pkg_size_info(STORAGE_TYPE_EXTERNAL_USER_PATH,
- pkgid, &pkg_size_info->ext_data_size,
+ pkgid, ext_image_path, &pkg_size_info->ext_data_size,
&pkg_size_info->ext_cache_size, &pkg_size_info->ext_app_size);
if (ret < 0) {
LOGE("failed to calculate external(user) size " \
{
int ret;
char *pkgid;
+ char *ext_image_path;
pkg_size_info_t temp_pkg_size_info = {0,};
pkg_size_info_t *pkg_size_info = (void *)user_data;
return -1;
}
- ret = __get_pkg_size_info(pkgid, &temp_pkg_size_info);
+ ext_image_path = __get_external_image_path_by_handle(handle);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, &temp_pkg_size_info);
if (ret < 0)
LOGW("failed to get size of some path");
/* even if it's an error, store all the valid result */
+ if (ext_image_path)
+ free(ext_image_path);
pkg_size_info->app_size += temp_pkg_size_info.app_size;
pkg_size_info->data_size += temp_pkg_size_info.data_size;
{
int ret;
char *pkgid;
+ char *ext_image_path;
int data_size = 0;
int total_size = 0;
char total_buf[MAX_PKG_BUF_LEN];
return -1;
}
- ret = __get_pkg_size_info(pkgid, &temp_pkg_size_info);
+ ext_image_path = __get_external_image_path_by_handle(handle);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, &temp_pkg_size_info);
if (ret < 0)
LOGW("failed to get size of some path");
/* even if it's an error, store all the valid result */
+ if (ext_image_path)
+ free(ext_image_path);
+
total_size = temp_pkg_size_info.app_size +
temp_pkg_size_info.data_size + temp_pkg_size_info.cache_size;
data_size = temp_pkg_size_info.data_size +
pkgmgr_installer *pi;
pkg_size_info_t info = {0, };
int fifo_exist = 0;
+ char *ext_image_path = NULL;
/* argv has bellowed meaning */
/* argv[1] = pkgid */
switch (get_type) {
case PM_GET_TOTAL_SIZE:
/* send result to file */
- ret = __get_pkg_size_info(pkgid, &info);
+ ext_image_path = __get_external_image_path_by_pkgid(pkgid);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, &info);
if (ret < 0)
LOGW("failed to get size of some path");
size = info.app_size + info.data_size + info.cache_size;
break;
case PM_GET_DATA_SIZE:
/* send result to file */
- ret = __get_pkg_size_info(pkgid, &info);
+ ext_image_path = __get_external_image_path_by_pkgid(pkgid);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, &info);
if (ret < 0)
LOGW("failed to get size of some path");
size = info.data_size + info.cache_size;
break;
case PM_GET_PKG_SIZE_INFO:
/* send result to signal */
- ret = __get_pkg_size_info(pkgid, &info);
+ ext_image_path = __get_external_image_path_by_pkgid(pkgid);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, &info);
if (ret < 0)
LOGW("failed to get size of some path");
size = info.app_size + info.data_size + info.cache_size;
LOGE("failed to send finished signal");
}
+ if (ext_image_path)
+ free(ext_image_path);
+
LOGD("get size result = %d", ret);
pkgmgr_installer_free(pi);