summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-06-24 12:32:45 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-06-24 12:32:45 +0000
commitb410863d6aae1e923ff163942adef01ff6a2ea81 (patch)
treea284e474904a9d1d4e1f80024da8cafc6d758ac0
parent677d87ec50b9e8cdf88c61be07ad8c6d7f68f9dd (diff)
parent9bc8c62ea4d86d948af7a2aade8b0b5502a84b6a (diff)
downloadframeworks_native-b410863d6aae1e923ff163942adef01ff6a2ea81.zip
frameworks_native-b410863d6aae1e923ff163942adef01ff6a2ea81.tar.gz
frameworks_native-b410863d6aae1e923ff163942adef01ff6a2ea81.tar.bz2
am 9bc8c62e: am 357df19b: Merge "Exclude subdirectories when pruning the dex cache."
* commit '9bc8c62ea4d86d948af7a2aade8b0b5502a84b6a': Exclude subdirectories when pruning the dex cache.
-rw-r--r--cmds/installd/commands.c31
-rw-r--r--cmds/installd/installd.c4
-rw-r--r--cmds/installd/installd.h2
3 files changed, 29 insertions, 8 deletions
diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c
index 974c865..01eb5ef 100644
--- a/cmds/installd/commands.c
+++ b/cmds/installd/commands.c
@@ -1384,10 +1384,11 @@ int restorecon_data(const char* pkgName, const char* seinfo, uid_t uid)
static int prune_dex_exclusion_predicate(const char *file_name, const int is_dir)
{
- // Don't exclude any directories, we want to inspect them
- // recusively for files.
+ // Exclude all directories. The top level command will be
+ // given a list of ISA specific directories that are assumed
+ // to be flat.
if (is_dir) {
- return 0;
+ return 1;
}
@@ -1405,6 +1406,26 @@ static int prune_dex_exclusion_predicate(const char *file_name, const int is_dir
return 1;
}
-int prune_dex_cache() {
- return delete_dir_contents(DALVIK_CACHE_PREFIX, 0, &prune_dex_exclusion_predicate);
+int prune_dex_cache(const char* subdir) {
+ // "." is handled as a special case, and refers to
+ // DALVIK_CACHE_PREFIX (usually /data/dalvik-cache).
+ const bool is_dalvik_cache_root = !strcmp(subdir, ".");
+
+ // Don't allow the path to contain "." or ".." except for the
+ // special case above. This is much stricter than we need to be,
+ // but there's no good reason to support them.
+ if (strchr(subdir, '.' ) != NULL && !is_dalvik_cache_root) {
+ return -1;
+ }
+
+ if (!is_dalvik_cache_root) {
+ char full_path[PKG_PATH_MAX];
+ snprintf(full_path, sizeof(full_path), "%s%s", DALVIK_CACHE_PREFIX, subdir);
+ return delete_dir_contents(full_path, 0, &prune_dex_exclusion_predicate);
+ }
+
+
+ // When subdir == ".", clean the contents of the top level
+ // dalvik-cache directory.
+ return delete_dir_contents(DALVIK_CACHE_PREFIX, 0, &prune_dex_exclusion_predicate);
}
diff --git a/cmds/installd/installd.c b/cmds/installd/installd.c
index 4368a9e..45cc2b2 100644
--- a/cmds/installd/installd.c
+++ b/cmds/installd/installd.c
@@ -143,7 +143,7 @@ static int do_restorecon_data(char **arg, char reply[REPLY_MAX] __attribute__((u
static int do_prune_dex_cache(char **arg __attribute__((unused)),
char reply[REPLY_MAX] __attribute__((unused)))
{
- return prune_dex_cache();
+ return prune_dex_cache(arg[0] /* subdirectory name */);
}
struct cmdinfo {
@@ -172,7 +172,7 @@ struct cmdinfo cmds[] = {
{ "rmuser", 1, do_rm_user },
{ "idmap", 3, do_idmap },
{ "restorecondata", 3, do_restorecon_data },
- { "prunedexcache", 0, do_prune_dex_cache },
+ { "prunedexcache", 1, do_prune_dex_cache },
};
static int readx(int s, void *_buf, int count)
diff --git a/cmds/installd/installd.h b/cmds/installd/installd.h
index c1e6e0f..f193b46 100644
--- a/cmds/installd/installd.h
+++ b/cmds/installd/installd.h
@@ -220,4 +220,4 @@ int movefiles();
int linklib(const char* target, const char* source, int userId);
int idmap(const char *target_path, const char *overlay_path, uid_t uid);
int restorecon_data();
-int prune_dex_cache();
+int prune_dex_cache(const char* subdir);