[incfs] Use the new IncFs_MakeDirs() function
This gets rid of annoying warnings in logcat about not being
able to create a directory and then directory already existing
Bug: 153704006
Test: atest IncrementalServiceTest
Test: adb install megacity.apk
Change-Id: Ib718960287f93cb383c06c9b9e3d0abf1ec42916
diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp
index 0641872..dc05cb6 100644
--- a/services/incremental/IncrementalService.cpp
+++ b/services/incremental/IncrementalService.cpp
@@ -212,6 +212,7 @@
template <class Func>
static auto makeCleanup(Func&& f) {
auto deleter = [f = std::move(f)](auto) { f(); };
+ // &f is a dangling pointer here, but we actually never use it as deleter moves it in.
return std::unique_ptr<Func, decltype(deleter)>(&f, std::move(deleter));
}
@@ -719,7 +720,7 @@
LOG(ERROR) << "no storage";
return -EINVAL;
}
- std::string normSource = normalizePathToStorageLocked(ifs, storageInfo, source);
+ std::string normSource = normalizePathToStorageLocked(*ifs, storageInfo, source);
if (normSource.empty()) {
LOG(ERROR) << "invalid source path";
return -EINVAL;
@@ -773,7 +774,7 @@
}
std::string IncrementalService::normalizePathToStorageLocked(
- const IfsMountPtr& incfs, IncFsMount::StorageMap::iterator storageIt,
+ const IncFsMount& incfs, IncFsMount::StorageMap::const_iterator storageIt,
std::string_view path) const {
if (!path::isAbsolute(path)) {
return path::normalize(path::join(storageIt->second.name, path));
@@ -783,19 +784,18 @@
return normPath;
}
// not that easy: need to find if any of the bind points match
- const auto bindIt = findParentPath(incfs->bindPoints, normPath);
- if (bindIt == incfs->bindPoints.end()) {
+ const auto bindIt = findParentPath(incfs.bindPoints, normPath);
+ if (bindIt == incfs.bindPoints.end()) {
return {};
}
return path::join(bindIt->second.sourceDir, path::relativize(bindIt->first, normPath));
}
-std::string IncrementalService::normalizePathToStorage(const IncrementalService::IfsMountPtr& ifs,
- StorageId storage,
+std::string IncrementalService::normalizePathToStorage(const IncFsMount& ifs, StorageId storage,
std::string_view path) const {
- std::unique_lock l(ifs->lock);
- const auto storageInfo = ifs->storages.find(storage);
- if (storageInfo == ifs->storages.end()) {
+ std::unique_lock l(ifs.lock);
+ const auto storageInfo = ifs.storages.find(storage);
+ if (storageInfo == ifs.storages.end()) {
return {};
}
return normalizePathToStorageLocked(ifs, storageInfo, path);
@@ -804,7 +804,7 @@
int IncrementalService::makeFile(StorageId storage, std::string_view path, int mode, FileId id,
incfs::NewFileParams params) {
if (auto ifs = getIfs(storage)) {
- std::string normPath = normalizePathToStorage(ifs, storage, path);
+ std::string normPath = normalizePathToStorage(*ifs, storage, path);
if (normPath.empty()) {
LOG(ERROR) << "Internal error: storageId " << storage
<< " failed to normalize: " << path;
@@ -822,7 +822,7 @@
int IncrementalService::makeDir(StorageId storageId, std::string_view path, int mode) {
if (auto ifs = getIfs(storageId)) {
- std::string normPath = normalizePathToStorage(ifs, storageId, path);
+ std::string normPath = normalizePathToStorage(*ifs, storageId, path);
if (normPath.empty()) {
return -EINVAL;
}
@@ -836,21 +836,16 @@
if (!ifs) {
return -EINVAL;
}
+ return makeDirs(*ifs, storageId, path, mode);
+}
+
+int IncrementalService::makeDirs(const IncFsMount& ifs, StorageId storageId, std::string_view path,
+ int mode) {
std::string normPath = normalizePathToStorage(ifs, storageId, path);
if (normPath.empty()) {
return -EINVAL;
}
- auto err = mIncFs->makeDir(ifs->control, normPath, mode);
- if (err == -EEXIST) {
- return 0;
- }
- if (err != -ENOENT) {
- return err;
- }
- if (auto err = makeDirs(storageId, path::dirname(normPath), mode)) {
- return err;
- }
- return mIncFs->makeDir(ifs->control, normPath, mode);
+ return mIncFs->makeDirs(ifs.control, normPath, mode);
}
int IncrementalService::link(StorageId sourceStorageId, std::string_view oldPath,
@@ -864,8 +859,8 @@
return -EINVAL;
}
l.unlock();
- std::string normOldPath = normalizePathToStorage(ifsSrc, sourceStorageId, oldPath);
- std::string normNewPath = normalizePathToStorage(ifsSrc, destStorageId, newPath);
+ std::string normOldPath = normalizePathToStorage(*ifsSrc, sourceStorageId, oldPath);
+ std::string normNewPath = normalizePathToStorage(*ifsSrc, destStorageId, newPath);
if (normOldPath.empty() || normNewPath.empty()) {
LOG(ERROR) << "Invalid paths in link(): " << normOldPath << " | " << normNewPath;
return -EINVAL;
@@ -875,7 +870,7 @@
int IncrementalService::unlink(StorageId storage, std::string_view path) {
if (auto ifs = getIfs(storage)) {
- std::string normOldPath = normalizePathToStorage(ifs, storage, path);
+ std::string normOldPath = normalizePathToStorage(*ifs, storage, path);
return mIncFs->unlink(ifs->control, normOldPath);
}
return -EINVAL;
@@ -960,7 +955,7 @@
if (!ifs) {
return {};
}
- const auto normPath = normalizePathToStorage(ifs, storage, path);
+ const auto normPath = normalizePathToStorage(*ifs, storage, path);
if (normPath.empty()) {
return {};
}
@@ -1363,7 +1358,7 @@
}
// First prepare target directories if they don't exist yet
- if (auto res = makeDirs(storage, libDirRelativePath, 0755)) {
+ if (auto res = makeDirs(*ifs, storage, libDirRelativePath, 0755)) {
LOG(ERROR) << "Failed to prepare target lib directory " << libDirRelativePath
<< " errno: " << res;
return false;
@@ -1401,7 +1396,7 @@
const auto libName = path::basename(fileName);
const auto targetLibPath = path::join(libDirRelativePath, libName);
- const auto targetLibPathAbsolute = normalizePathToStorage(ifs, storage, targetLibPath);
+ const auto targetLibPathAbsolute = normalizePathToStorage(*ifs, storage, targetLibPath);
// If the extract file already exists, skip
if (access(targetLibPathAbsolute.c_str(), F_OK) == 0) {
if (perfLoggingEnabled()) {