return 0;
}
-static char *__get_external_image_path_by_handle(pkgmgrinfo_pkginfo_h handle)
+static char *__get_external_tep_path_by_handle(pkgmgrinfo_pkginfo_h handle)
{
int ret;
char *result_path;
+ char *sdpath;
- ret = pkgmgrinfo_pkginfo_get_external_image_path(handle, &result_path);
+ ret = pkgmgrinfo_pkginfo_get_tep_name(handle, &result_path);
if (ret != PMINFO_R_OK)
return NULL;
+ ret = __get_sdcard_path(&sdpath);
+ if (ret < 0)
+ return NULL;
+
+ if (strstr(result_path, sdpath) == NULL)
+ return NULL;
+
return strdup(result_path);
}
-static char *__get_external_image_path_by_pkgid(const char *pkgid)
+static char *__get_external_image_path_by_handle(pkgmgrinfo_pkginfo_h handle)
{
int ret;
char *result_path;
- pkgmgrinfo_pkginfo_h handle;
- ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ ret = pkgmgrinfo_pkginfo_get_external_image_path(handle, &result_path);
if (ret != PMINFO_R_OK)
return NULL;
- result_path = __get_external_image_path_by_handle(handle);
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-
- return result_path;
+ return strdup(result_path);
}
static long long __calculate_directory_size(int dfd, bool include_itself)
return -1;
}
+static int __calculate_tep_dir_size(int dfd)
+{
+ long long size = 0;
+ struct stat st;
+ int ret;
+ DIR *dir;
+ struct dirent *dent = NULL;
+ const char *file_info;
+ char buf[1024] = {0, };
+
+ ret = fstat(dfd, &st);
+ if (ret < 0) {
+ LOGE("fstat() failed, file_info: ., errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ }
+ size += __stat_size(&st);
+
+ dir = fdopendir(dfd);
+ if (dir == NULL) {
+ LOGE("fdopendir() failed, errno: %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ return -1;
+ }
+
+ while ((dent = readdir(dir)) != NULL) {
+ file_info = dent->d_name;
+ if (file_info[0] == '.') {
+ if (file_info[1] == '\0')
+ continue;
+ if ((file_info[1] == '.') && (file_info[2] == '\0'))
+ continue;
+ }
+
+ if (strncmp(file_info, "mount", strlen("mount")) == 0)
+ continue;
+
+ ret = fstatat(dfd, file_info, &st, AT_SYMLINK_NOFOLLOW);
+ if (ret < 0) {
+ LOGE("fstatat() failed, file_info:%s, errno: %d(%s)",
+ file_info, errno, strerror_r(errno, buf, sizeof(buf)));
+ goto error;
+ }
+ size += __stat_size(&st);
+ }
+
+ closedir(dir);
+ return size;
+
+error:
+ closedir(dir);
+ return -1;
+}
+
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)
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)
+ const char *ext_tep_path, long long *data_size,
+ long long *cache_size, long long *app_size)
{
char app_root_dir[MAX_PATH_LENGTH] = {0, };
char buf[1024] = {0, };
}
/* external image file */
*app_size += __stat_size(&st);
+ LOGD("app_size: %lld", *app_size);
+ close(subfd);
+ }
+ }
+ if (ext_tep_path) {
+ subfd = open(ext_tep_path, O_RDONLY);
+ if (subfd < 0) {
+ LOGE("open() failed, path: %s, errno: %d (%s)",
+ ext_tep_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_tep_path, errno,
+ strerror_r(errno, buf,
+ sizeof(buf)));
+ close(subfd);
+ return -1;
+ }
+ /* external tep file */
+ *app_size += __stat_size(&st);
+ LOGD("app_size: %lld", *app_size);
close(subfd);
}
}
if (dent->d_type != DT_DIR)
continue;
+ if (strncmp(name, ".pkg", strlen(".pkg")) == 0 ||
+ strncmp(name, ".mmc", strlen(".mmc")) == 0)
+ continue;
+
subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY);
if (subfd < 0) {
if (errno != ENOENT) {
goto error;
}
LOGD("app_size: %lld", *app_size);
+ } else if (strncmp(name, "tep", strlen("tep")) == 0) {
+ LOGD("traverse path: %s/%s", app_root_dir, name);
+ size = __calculate_tep_dir_size(subfd);
+ if (size < 0) {
+ LOGE("Calculating tep directory failed.");
+ goto error;
+ }
+ *app_size += size;
+ LOGD("app_size: %lld", *app_size);
} else {
LOGD("traverse path: %s/%s", app_root_dir, name);
size = __calculate_directory_size(subfd, true);
}
static int __get_pkg_size_info(const char *pkgid, const char *ext_image_path,
- pkg_size_info_t *pkg_size_info)
+ const char *ext_tep_path, pkg_size_info_t *pkg_size_info)
{
int ret;
ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL_GLOBAL_PATH,
- pkgid, ext_image_path, &pkg_size_info->data_size,
+ pkgid, ext_image_path, ext_tep_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, ext_image_path, &pkg_size_info->data_size,
+ pkgid, ext_image_path, ext_tep_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, ext_image_path, &pkg_size_info->ext_data_size,
- &pkg_size_info->ext_cache_size, &pkg_size_info->ext_app_size);
+ pkgid, ext_image_path, ext_tep_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 " \
"for pkgid(%s)", pkgid);
int ret;
char *pkgid;
char *ext_image_path;
+ char *ext_tep_path;
pkg_size_info_t temp_pkg_size_info = {0,};
pkg_size_info_t *pkg_size_info = (void *)user_data;
}
ext_image_path = __get_external_image_path_by_handle(handle);
- ret = __get_pkg_size_info(pkgid, ext_image_path, &temp_pkg_size_info);
+ ext_tep_path = __get_external_tep_path_by_handle(handle);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_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);
+ if (ext_tep_path)
+ free(ext_tep_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;
+ char *ext_tep_path;
int data_size = 0;
int total_size = 0;
char total_buf[MAX_PKG_BUF_LEN];
}
ext_image_path = __get_external_image_path_by_handle(handle);
- ret = __get_pkg_size_info(pkgid, ext_image_path, &temp_pkg_size_info);
+ ext_tep_path = __get_external_tep_path_by_handle(handle);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_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);
+ if (ext_tep_path)
+ free(ext_tep_path);
total_size = temp_pkg_size_info.app_size +
temp_pkg_size_info.data_size + temp_pkg_size_info.cache_size;
pkg_size_info_t info = {0, };
int fifo_exist = 0;
char *ext_image_path = NULL;
+ char *ext_tep_path = NULL;
+ pkgmgrinfo_pkginfo_h handle;
/* argv has bellowed meaning */
/* argv[1] = pkgid */
"caller_uid=%d, fifo_exist=%d]",
pkgid, get_type, target_uid, caller_uid, fifo_exist);
+ if (get_type == PM_GET_TOTAL_SIZE ||
+ get_type == PM_GET_DATA_SIZE ||
+ get_type == PM_GET_PKG_SIZE_INFO) {
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret == PMINFO_R_OK) {
+ ext_image_path =
+ __get_external_image_path_by_handle(handle);
+ ext_tep_path =
+ __get_external_tep_path_by_handle(handle);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ }
+ }
+
switch (get_type) {
case PM_GET_TOTAL_SIZE:
/* send result to file */
- ext_image_path = __get_external_image_path_by_pkgid(pkgid);
- ret = __get_pkg_size_info(pkgid, ext_image_path, &info);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_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 */
- ext_image_path = __get_external_image_path_by_pkgid(pkgid);
- ret = __get_pkg_size_info(pkgid, ext_image_path, &info);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_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 */
- ext_image_path = __get_external_image_path_by_pkgid(pkgid);
- ret = __get_pkg_size_info(pkgid, ext_image_path, &info);
+ ret = __get_pkg_size_info(pkgid, ext_image_path, ext_tep_path,
+ &info);
if (ret < 0)
LOGW("failed to get size of some path");
size = info.app_size + info.data_size + info.cache_size;
if (ext_image_path)
free(ext_image_path);
+ if (ext_tep_path)
+ free(ext_tep_path);
LOGD("get size result = %d", ret);
pkgmgr_installer_free(pi);