From d712f0ccc120357e1267a04ac6de9dd732b27e76 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 3 May 2017 11:36:42 -0600 Subject: Clear cached files on external storage. When clearing cached files belonging to an app, include any cached files on external storage. Since we need to keep sdcardfs in the loop about any file deletions, we always mutate by going through the sdcardfs layer instead of behind its back. Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest Bug: 37486230, 37566983, 37913442, 37914374 Change-Id: If174bf7eaf682da83cf0ab1b4938fe9a5956d464 --- cmds/installd/CacheItem.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'cmds/installd/CacheItem.cpp') diff --git a/cmds/installd/CacheItem.cpp b/cmds/installd/CacheItem.cpp index 17eb7ff0e1..515f915b8b 100644 --- a/cmds/installd/CacheItem.cpp +++ b/cmds/installd/CacheItem.cpp @@ -67,6 +67,7 @@ std::string CacheItem::buildPath() { } int CacheItem::purge() { + int res = 0; auto path = buildPath(); if (directory) { FTS *fts; @@ -88,29 +89,47 @@ int CacheItem::purge() { break; case FTS_F: if (p->fts_parent->fts_number) { - truncate(p->fts_path, 0); + if (truncate(p->fts_path, 0) != 0) { + PLOG(WARNING) << "Failed to truncate " << p->fts_path; + res = -1; + } } else { - unlink(p->fts_path); + if (unlink(p->fts_path) != 0) { + PLOG(WARNING) << "Failed to unlink " << p->fts_path; + res = -1; + } } break; case FTS_DEFAULT: case FTS_SL: case FTS_SLNONE: - unlink(p->fts_path); + if (unlink(p->fts_path) != 0) { + PLOG(WARNING) << "Failed to unlink " << p->fts_path; + res = -1; + } break; case FTS_DP: - rmdir(p->fts_path); + if (rmdir(p->fts_path) != 0) { + PLOG(WARNING) << "Failed to rmdir " << p->fts_path; + res = -1; + } break; } } - return 0; } else { if (tombstone) { - return truncate(path.c_str(), 0); + if (truncate(path.c_str(), 0) != 0) { + PLOG(WARNING) << "Failed to truncate " << path; + res = -1; + } } else { - return unlink(path.c_str()); + if (unlink(path.c_str()) != 0) { + PLOG(WARNING) << "Failed to unlink " << path; + res = -1; + } } } + return res; } } // namespace installd -- cgit v1.2.3-59-g8ed1b