OSDN Git Service

Don't report errors when trying to delete a non-existing profile dir
authorCalin Juravle <calin@google.com>
Mon, 28 Mar 2016 14:11:01 +0000 (15:11 +0100)
committerCalin Juravle <calin@google.com>
Mon, 28 Mar 2016 15:43:10 +0000 (16:43 +0100)
Also, put destroy_app_current_profiles behind FLAG_STORAGE_DE flag.

Bug: 27081617
Change-Id: Ib8b9ff292784c659259ceb4339b803e3580da7ed

cmds/installd/commands.cpp
cmds/installd/utils.cpp
cmds/installd/utils.h

index 8350da7..ff5a3b8 100644 (file)
@@ -235,7 +235,9 @@ int clear_app_data(const char *uuid, const char *pkgname, userid_t userid, int f
 }
 
 static int destroy_app_current_profiles(const char *pkgname, userid_t userid) {
-    return delete_dir_contents_and_dir(create_data_user_profile_package_path(userid, pkgname));
+    return delete_dir_contents_and_dir(
+        create_data_user_profile_package_path(userid, pkgname),
+        /*ignore_if_missing*/ true);
 }
 
 int destroy_app_profiles(const char *pkgname) {
@@ -244,7 +246,9 @@ int destroy_app_profiles(const char *pkgname) {
     for (auto user : users) {
         result |= destroy_app_current_profiles(pkgname, user);
     }
-    result |= delete_dir_contents_and_dir(create_data_ref_profile_package_path(pkgname));
+    result |= delete_dir_contents_and_dir(
+        create_data_ref_profile_package_path(pkgname),
+        /*ignore_if_missing*/ true);
     return result;
 }
 
@@ -257,8 +261,8 @@ int destroy_app_data(const char *uuid, const char *pkgname, userid_t userid, int
     if (flags & FLAG_STORAGE_DE) {
         res |= delete_dir_contents_and_dir(
                 create_data_user_de_package_path(uuid, userid, pkgname));
+        destroy_app_current_profiles(pkgname, userid);
     }
-    destroy_app_current_profiles(pkgname, userid);
     return res;
 }
 
index 74f4264..d84d9f6 100644 (file)
@@ -341,23 +341,27 @@ static int _delete_dir_contents(DIR *d,
     return result;
 }
 
-int delete_dir_contents(const std::string& pathname) {
-    return delete_dir_contents(pathname.c_str(), 0, NULL);
+int delete_dir_contents(const std::string& pathname, bool ignore_if_missing) {
+    return delete_dir_contents(pathname.c_str(), 0, NULL, ignore_if_missing);
 }
 
-int delete_dir_contents_and_dir(const std::string& pathname) {
-    return delete_dir_contents(pathname.c_str(), 1, NULL);
+int delete_dir_contents_and_dir(const std::string& pathname, bool ignore_if_missing) {
+    return delete_dir_contents(pathname.c_str(), 1, NULL, ignore_if_missing);
 }
 
 int delete_dir_contents(const char *pathname,
                         int also_delete_dir,
-                        int (*exclusion_predicate)(const char*, const int))
+                        int (*exclusion_predicate)(const char*, const int),
+                        bool ignore_if_missing)
 {
     int res = 0;
     DIR *d;
 
     d = opendir(pathname);
     if (d == NULL) {
+        if (ignore_if_missing && (errno == ENOENT)) {
+            return 0;
+        }
         ALOGE("Couldn't opendir %s: %s\n", pathname, strerror(errno));
         return -errno;
     }
index 9bbddca..416a726 100644 (file)
@@ -99,12 +99,13 @@ int create_move_path(char path[PKG_PATH_MAX],
 
 int is_valid_package_name(const char* pkgname);
 
-int delete_dir_contents(const std::string& pathname);
-int delete_dir_contents_and_dir(const std::string& pathname);
+int delete_dir_contents(const std::string& pathname, bool ignore_if_missing = false);
+int delete_dir_contents_and_dir(const std::string& pathname, bool ignore_if_missing = false);
 
 int delete_dir_contents(const char *pathname,
                         int also_delete_dir,
-                        int (*exclusion_predicate)(const char *name, const int is_dir));
+                        int (*exclusion_predicate)(const char *name, const int is_dir),
+                        bool ignore_if_missing = false);
 
 int delete_dir_contents_fd(int dfd, const char *name);