Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9b81cee authored by Calin Juravle's avatar Calin Juravle Committed by android-build-merger
Browse files

Don\'t report errors when trying to delete a non-existing profile dir

am: b06f98aa

* commit 'b06f98aa':
  Don't report errors when trying to delete a non-existing profile dir
parents eba287f3 b06f98aa
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -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);
    }
    return res;
}

+9 −5
Original line number Diff line number Diff line
@@ -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;
    }
+4 −3
Original line number Diff line number Diff line
@@ -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);