Skip to content

Commit 3720ff3

Browse files
adelva1984rmuthiah
authored andcommitted
Check for errors from EnsureDirectoryExists/RenameFile
The return values of these functions are not supposed to be ignored. Check them and handle appropriately. Bug: 385004915 Test: m Change-Id: I96a780dd5e8475130f2ea04ea4b7a8ffbbbb39cf
1 parent dffb2f9 commit 3720ff3

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

common/libs/utils/files.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Result<void> EnsureDirectoryExists(const std::string& directory_path,
186186
}
187187
const auto parent_dir = android::base::Dirname(directory_path);
188188
if (parent_dir.size() > 1) {
189-
EnsureDirectoryExists(parent_dir, mode, group_name);
189+
CF_EXPECT(EnsureDirectoryExists(parent_dir, mode, group_name));
190190
}
191191
LOG(VERBOSE) << "Setting up " << directory_path;
192192
if (mkdir(directory_path.c_str(), mode) < 0 && errno != EEXIST) {

host/commands/assemble_cvd/vendor_dlkm_utils.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,20 @@ bool SplitRamdiskModules(const std::string& ramdisk_path,
458458
if (IsKernelModuleSigned(module_location)) {
459459
const auto system_dlkm_module_location =
460460
fmt::format("{}/{}", system_modules_dir, module_path);
461-
EnsureDirectoryExists(
461+
auto res = EnsureDirectoryExists(
462462
android::base::Dirname(system_dlkm_module_location));
463-
RenameFile(module_location, system_dlkm_module_location);
463+
CHECK(res.ok()) << res.error().FormatForEnv();
464+
auto ret = RenameFile(module_location, system_dlkm_module_location);
465+
CHECK(ret.ok()) << ret.error().FormatForEnv();
464466
system_dlkm_modules.emplace(module_path);
465467
} else {
466468
const auto vendor_dlkm_module_location =
467469
fmt::format("{}/{}", vendor_modules_dir, module_path);
468-
EnsureDirectoryExists(
470+
auto res = EnsureDirectoryExists(
469471
android::base::Dirname(vendor_dlkm_module_location));
470-
RenameFile(module_location, vendor_dlkm_module_location);
472+
CHECK(res.ok()) << res.error().FormatForEnv();
473+
auto ret = RenameFile(module_location, vendor_dlkm_module_location);
474+
CHECK(ret.ok()) << ret.error().FormatForEnv();
471475
vendor_dlkm_modules.emplace(module_path);
472476
}
473477
}
@@ -492,7 +496,8 @@ bool SplitRamdiskModules(const std::string& ramdisk_path,
492496
if (FileExists(initramfs_blocklist_path)) {
493497
const auto vendor_dlkm_blocklist_path =
494498
fmt::format("{}/{}", vendor_modules_dir, "modules.blocklist");
495-
RenameFile(initramfs_blocklist_path, vendor_dlkm_blocklist_path);
499+
auto ret = RenameFile(initramfs_blocklist_path, vendor_dlkm_blocklist_path);
500+
CHECK(ret.ok()) << ret.error().FormatForEnv();
496501
}
497502

498503
// Write updated modules.dep and modules.load files

0 commit comments

Comments
 (0)