From a44fee955aeb3dc8f4cf3de078ba02c75386c502 Mon Sep 17 00:00:00 2001 From: Sergio Andres Rodriguez Orama Date: Fri, 21 Jun 2024 17:16:17 -0400 Subject: Do not return "." and ".." special entries in `DirectoryContents`. Follow up of comment: https://android-review.git.corp.google.com/c/device/google/cuttlefish/+/3141577/comment/28b6d202_89c55529/ Test: n/a Bug: n/a Change-Id: I4487300ff6aafa70b5acda4cdf933d97a2ab419d --- host/commands/assemble_cvd/assemble_cvd.cc | 3 --- host/commands/host_bugreport/main.cc | 12 ------------ host/libs/command_util/snapshot_utils.cc | 4 ---- host/libs/config/custom_actions.cpp | 5 ++--- host/libs/config/host_tools_version.cpp | 7 ------- 5 files changed, 2 insertions(+), 29 deletions(-) (limited to 'host') diff --git a/host/commands/assemble_cvd/assemble_cvd.cc b/host/commands/assemble_cvd/assemble_cvd.cc index c386c3d48..2f0fc18f7 100644 --- a/host/commands/assemble_cvd/assemble_cvd.cc +++ b/host/commands/assemble_cvd/assemble_cvd.cc @@ -319,9 +319,6 @@ Result InitFilesystemAndCreateConfig( const auto log_files = CF_EXPECT(DirectoryContents(instance.PerInstanceLogPath(""))); for (const auto& filename : log_files) { - if (filename == "." || filename == "..") { - continue; - } const std::string path = instance.PerInstanceLogPath(filename); auto fd = SharedFD::Open(path, O_WRONLY | O_APPEND); CF_EXPECT(fd->IsOpen(), diff --git a/host/commands/host_bugreport/main.cc b/host/commands/host_bugreport/main.cc index fc68c41eb..a414dfc85 100644 --- a/host/commands/host_bugreport/main.cc +++ b/host/commands/host_bugreport/main.cc @@ -62,9 +62,6 @@ Result AddNetsimdLogs(ZipWriter& writer) { auto names = CF_EXPECTF(DirectoryContents(dir), "Cannot read from {} directory.", dir); for (const auto& name : names) { - if (name == "." || name == "..") { - continue; - } SaveFile(writer, "netsimd/" + name, dir + "/" + name); } return {}; @@ -99,9 +96,6 @@ Result CvdHostBugreportMain(int argc, char** argv) { auto logs = CF_EXPECT(DirectoryContents(instance.PerInstancePath("logs")), "Cannot read from logs directory."); for (const auto& log : logs) { - if (log == "." || log == "..") { - continue; - } save("logs/" + log); } } else { @@ -114,18 +108,12 @@ Result CvdHostBugreportMain(int argc, char** argv) { CF_EXPECT(DirectoryContents(instance.PerInstancePath("tombstones")), "Cannot read from tombstones directory."); for (const auto& tombstone : tombstones) { - if (tombstone == "." || tombstone == "..") { - continue; - } save("tombstones/" + tombstone); } auto recordings = CF_EXPECT(DirectoryContents(instance.PerInstancePath("recording")), "Cannot read from recording directory."); for (const auto& recording : recordings) { - if (recording == "." || recording == "..") { - continue; - } save("recording/" + recording); } } diff --git a/host/libs/command_util/snapshot_utils.cc b/host/libs/command_util/snapshot_utils.cc index 4161ee8a4..ccb427a29 100644 --- a/host/libs/command_util/snapshot_utils.cc +++ b/host/libs/command_util/snapshot_utils.cc @@ -70,10 +70,6 @@ Result CopyDirectoryImpl( if (!predicate(src_dir_path + "/" + src_base_path)) { continue; } - if (src_base_path == "." || src_base_path == "..") { - LOG(DEBUG) << "Skipping \"" << src_base_path << "\""; - continue; - } std::string src_path = src_dir_path + "/" + src_base_path; std::string dest_path = dest_dir_path + "/" + src_base_path; diff --git a/host/libs/config/custom_actions.cpp b/host/libs/config/custom_actions.cpp index 9254d57bb..207f5d181 100644 --- a/host/libs/config/custom_actions.cpp +++ b/host/libs/config/custom_actions.cpp @@ -176,11 +176,10 @@ std::string DefaultCustomActionConfig() { CHECK(directory_contents_result.ok()) << directory_contents_result.error().FormatForEnv(); auto custom_action_configs = std::move(*directory_contents_result); - // Two entries are always . and .. - if (custom_action_configs.size() > 3) { + if (custom_action_configs.size() > 1) { LOG(ERROR) << "Expected at most one custom action config in " << custom_action_config_dir << ". Please delete extras."; - } else if (custom_action_configs.size() == 3) { + } else if (custom_action_configs.size() == 1) { for (const auto& config : custom_action_configs) { if (android::base::EndsWithIgnoreCase(config, ".json")) { return custom_action_config_dir + "/" + config; diff --git a/host/libs/config/host_tools_version.cpp b/host/libs/config/host_tools_version.cpp index 9ef895d0b..5c73e5c89 100644 --- a/host/libs/config/host_tools_version.cpp +++ b/host/libs/config/host_tools_version.cpp @@ -48,13 +48,6 @@ static std::map DirectoryCrc(const std::string& path) { auto files_result = DirectoryContents(full_path); CHECK(files_result.ok()) << files_result.error().FormatForEnv(); std::vector files = std::move(*files_result); - for (auto it = files.begin(); it != files.end();) { - if (*it == "." || *it == "..") { - it = files.erase(it); - } else { - it++; - } - } std::vector> calculations; calculations.reserve(files.size()); for (auto& file : files) { -- cgit v1.2.3