return 0;
}
+static int __remove_file(const char *pkgid, const char *file_path)
+{
+ int ret;
+ char filename[PATH_MAX];
+ const char *rootpath;
+ pkgmgrinfo_pkginfo_h pkg_handle = NULL;
+ char *pkg_type = NULL;
+ struct stat st_file_info;
+ char buf[1024] = {0, };
+
+ if (pkgid == NULL || file_path == NULL) {
+ LOGE("parameter is NULL");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkg_handle);
+ if (ret != PMINFO_R_OK) {
+ LOGE("Failed to get pkginfo");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_type(pkg_handle, &pkg_type);
+ if (ret != PMINFO_R_OK) {
+ LOGE("Failed to get type");
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+ return -1;
+ }
+
+ tzplatform_set_user(uid);
+ rootpath = tzplatform_getenv(TZ_USER_APP);
+
+ __send_signal(pkgid, pkg_type,
+ PKGMGR_INSTALLER_START_KEY_STR,
+ PKGMGR_INSTALLER_CLEAR_EVENT_STR);
+
+ snprintf(filename, sizeof(filename), "%s/%s/data/%s",
+ rootpath, pkgid, file_path);
+ if (lstat(filename, &st_file_info) < 0)
+ perror(filename);
+
+ if (S_ISDIR(st_file_info.st_mode)) {
+ ret = __clear_dir(file_path);
+ if (ret != 0) {
+ LOGE("Couldn't remove the directory. errno : %d (%s)",
+ errno, strerror_r(errno, buf, sizeof(buf)));
+ }
+ }
+
+ ret = remove(filename);
+ if (ret != 0) {
+ LOGE("Couldn't remove the directory. errno : %d (%s)", errno,
+ strerror_r(errno, buf, sizeof(buf)));
+ __send_signal(pkgid, pkg_type,
+ PKGMGR_INSTALLER_END_KEY_STR,
+ PKGMGR_INSTALLER_FAIL_EVENT_STR);
+ } else {
+ __send_signal(pkgid, pkg_type, PKGMGR_INSTALLER_END_KEY_STR,
+ PKGMGR_INSTALLER_OK_EVENT_STR);
+
+ }
+
+ tzplatform_reset_user();
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+ return ret;
+}
+
static void print_usage(void)
{
printf("pkg data/cache clear tool\n");
printf("\n");
printf("-c, --cache clear pkg's cache\n");
printf("-d, --data clear pkg's data\n");
+ printf("-f, --file remove a pkg's file or directory\n");
printf("-h, --help print this help\n");
printf("-n, --pkgid package id\n");
printf("-u, --uid user id\n");
printf("pkg_cleardata -c -n <pkgid> -u <uid>\n");
printf("pkg_cleardata -d -n <pkgid> -u <uid>\n");
printf("pkg_cleardata -cd -n <pkgid> -u <uid>\n");
+ printf("pkg_cleardata -n <pkgid> -u <uid> -f <file_path>\n");
printf("\n");
}
int c = -1;
int opt_idx = 0;
char pkgid[MAX_PKG_NAME_LEN] = { 0, };
+ char file_path[MAX_PKG_NAME_LEN] = { 0, };
bool clear_cache = false;
bool clear_data = false;
- const char short_options[] = "cdhn:u:";
+ const char short_options[] = "cdhn:u:f:";
const struct option long_options[] = {
{"cache", 0, NULL, 'c'},
{"data", 0, NULL, 'd'},
{"help", 0, NULL, 'h'},
{"pkgid", 1, NULL, 'n'},
{"uid", 1, NULL, 'u'},
+ {"file", 1, NULL, 'f'},
{0, 0, 0, 0} /* sentinel */
};
print_usage();
return -1;
}
+ break;
+ case 'f':
+ if (optarg) {
+ snprintf(file_path, sizeof(file_path), "%s", optarg);
+ } else {
+ print_usage();
+ return -1;
+ }
+ break;
default:
break;
}
}
- if ((!clear_cache && !clear_data) || (pkgid[0] == '\0') || uid == 0) {
+ if ((file_path[0] == '\0' && !clear_cache && !clear_data) ||
+ (pkgid[0] == '\0') || uid == 0) {
print_usage();
return -1;
}
ret = __clear_data_dir(pkgid);
}
+ if (!clear_data && !clear_cache && file_path[0] != '\0') {
+ pkgmgr_installer_set_request_type(pi, PKGMGR_REQ_CLEAR);
+ ret = __remove_file(pkgid, file_path);
+ }
+
pkgmgr_installer_free(pi);
return ret;