From b43b8ffdc9d0bf2defc14b9e9a30ef40d852c24b Mon Sep 17 00:00:00 2001 From: "A. Cody Schuffelen" Date: Tue, 4 Aug 2026 18:25:28 -0700 Subject: [PATCH] Move RemoveFile out of utils:files Bug: b/543573091 --- .../cuttlefish/common/libs/utils/BUILD.bazel | 1 + .../cuttlefish/common/libs/utils/files.cpp | 9 +---- base/cvd/cuttlefish/common/libs/utils/files.h | 1 - .../host/commands/assemble_cvd/BUILD.bazel | 3 ++ .../commands/assemble_cvd/assemble_cvd.cc | 1 + .../host/commands/assemble_cvd/boot_config.cc | 1 + .../commands/assemble_cvd/boot_image_utils.cc | 1 + .../host/commands/cvd/cli/BUILD.bazel | 3 +- .../commands/cvd/cli/commands/BUILD.bazel | 1 + .../host/commands/cvd/cli/commands/create.cpp | 1 + .../host/commands/cvd/cli/commands/start.cpp | 1 + .../host/commands/cvd/cli/log_files.cpp | 2 +- .../host/commands/cvd/fetch/BUILD.bazel | 1 + .../host/commands/cvd/fetch/fetch_context.cc | 1 + .../host/commands/cvd/instances/BUILD.bazel | 2 + .../cvd/instances/instance_manager.cpp | 1 + .../commands/cvd/instances/lock/BUILD.bazel | 1 + .../cvd/instances/lock/instance_lock.cpp | 1 + .../host/commands/cvd/instances/stop.cpp | 1 + .../host/commands/host_bugreport/BUILD.bazel | 2 +- .../host/commands/host_bugreport/main.cc | 2 +- .../host/commands/run_cvd/BUILD.bazel | 1 + .../commands/run_cvd/server_loop_impl.cpp | 1 + .../host/libs/command_util/BUILD.bazel | 1 + .../host/libs/command_util/snapshot_utils.cc | 1 + .../cuttlefish/host/libs/config/BUILD.bazel | 1 + .../host/libs/config/data_image.cpp | 1 + .../cuttlefish/host/libs/web/cas/BUILD.bazel | 2 + .../host/libs/web/cas/cas_downloader.cpp | 1 + .../host/libs/web/cas/cas_downloader_test.cpp | 1 + .../host/libs/web/http_client/BUILD.bazel | 1 + .../host/libs/web/http_client/http_file.cc | 1 + base/cvd/cuttlefish/posix/BUILD.bazel | 12 ++++++ base/cvd/cuttlefish/posix/remove.cc | 40 +++++++++++++++++++ base/cvd/cuttlefish/posix/remove.h | 26 ++++++++++++ 35 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 base/cvd/cuttlefish/posix/remove.cc create mode 100644 base/cvd/cuttlefish/posix/remove.h diff --git a/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel b/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel index 6cd6074620b..3ae295e5b4e 100644 --- a/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel +++ b/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel @@ -121,6 +121,7 @@ cf_cc_library( "//cuttlefish/files:file_exists", "//cuttlefish/files:link_or_copy", "//cuttlefish/posix:realpath", + "//cuttlefish/posix:remove", "//cuttlefish/posix:rename", "//cuttlefish/posix:strerror", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/common/libs/utils/files.cpp b/base/cvd/cuttlefish/common/libs/utils/files.cpp index 203f813ba16..785445d95ad 100644 --- a/base/cvd/cuttlefish/common/libs/utils/files.cpp +++ b/base/cvd/cuttlefish/common/libs/utils/files.cpp @@ -59,6 +59,7 @@ #include "cuttlefish/files/file_exists.h" #include "cuttlefish/files/link_or_copy.h" #include "cuttlefish/posix/realpath.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/rename.h" #include "cuttlefish/posix/strerror.h" #include "cuttlefish/result/result.h" @@ -268,14 +269,6 @@ Result RenameFile(const std::string& current_filepath, return target_filepath; } -Result RemoveFile(const std::string& file) { - VLOG(0) << "Removing file " << file; - if (remove(file.c_str()) != 0) { - return CF_ERRF("Failed to remove file '{}' : {}", file, StrError(errno)); - } - return {}; -} - std::string ReadFile(const std::string& file) { std::string contents; std::ifstream in(file, std::ios::in | std::ios::binary); diff --git a/base/cvd/cuttlefish/common/libs/utils/files.h b/base/cvd/cuttlefish/common/libs/utils/files.h index e2ed23cff55..c0ff43f6d75 100644 --- a/base/cvd/cuttlefish/common/libs/utils/files.h +++ b/base/cvd/cuttlefish/common/libs/utils/files.h @@ -53,7 +53,6 @@ Result ChangeGroup(const std::string& path, bool CanAccess(const std::string& path, int mode); Result IsDirectoryEmpty(const std::string& path); off_t FileSize(const std::string& path); -Result RemoveFile(const std::string& file); Result RenameFile(const std::string& current_filepath, const std::string& target_filepath); std::string ReadFile(const std::string& file); diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel b/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel index b4853e1d16a..0648a926bea 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel @@ -83,6 +83,7 @@ cf_cc_binary( "//cuttlefish/host/libs/feature", "//cuttlefish/host/libs/feature:inject", "//cuttlefish/host/libs/log_names", + "//cuttlefish/posix:remove", "//cuttlefish/posix:symlink", "//cuttlefish/pretty:vector", "//cuttlefish/result", @@ -110,6 +111,7 @@ cf_cc_library( "//cuttlefish/host/libs/config:kernel_args", "//cuttlefish/host/libs/config:mkenvimage_slim", "//cuttlefish/host/libs/vm_manager", + "//cuttlefish/posix:remove", "//cuttlefish/result", "@abseil-cpp//absl/log", "@abseil-cpp//absl/strings", @@ -143,6 +145,7 @@ cf_cc_library( "//cuttlefish/io:shared_fd", "//cuttlefish/io:string", "//cuttlefish/io:write_exact", + "//cuttlefish/posix:remove", "//cuttlefish/process:command", "//cuttlefish/process:execute", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd.cc index 38aaff0c049..217b9ad6181 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd.cc @@ -101,6 +101,7 @@ #include "cuttlefish/host/libs/feature/feature.h" #include "cuttlefish/host/libs/feature/inject.h" #include "cuttlefish/host/libs/log_names/log_names.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/symlink.h" #include "cuttlefish/pretty/vector.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_config.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_config.cc index 005949fe1f9..9958943f638 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_config.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_config.cc @@ -46,6 +46,7 @@ #include "cuttlefish/host/libs/config/kernel_args.h" #include "cuttlefish/host/libs/config/mkenvimage_slim.h" #include "cuttlefish/host/libs/vm_manager/crosvm_manager.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/result/result.h" using cuttlefish::vm_manager::CrosvmManager; diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_image_utils.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_image_utils.cc index c7303eb7974..7ebc707e37a 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_image_utils.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_image_utils.cc @@ -57,6 +57,7 @@ #include "cuttlefish/io/shared_fd.h" #include "cuttlefish/io/string.h" #include "cuttlefish/io/write_exact.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/process/command.h" #include "cuttlefish/process/execute.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel index 76a9988d12b..036808fba55 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel @@ -77,10 +77,10 @@ cf_cc_library( hdrs = ["log_files.h"], include_cleaner_enabled = False, deps = [ - "//cuttlefish/common/libs/utils:files", "//cuttlefish/files:directory_contents", "//cuttlefish/files:directory_exists", "//cuttlefish/host/commands/cvd/utils", + "//cuttlefish/posix:remove", "//cuttlefish/result", "@abseil-cpp//absl/log", "@abseil-cpp//absl/strings", @@ -171,6 +171,7 @@ cf_cc_library( "//cuttlefish/host/commands/cvd/instances/lock", "//cuttlefish/host/commands/cvd/utils", "//cuttlefish/posix:realpath", + "//cuttlefish/posix:remove", "//cuttlefish/posix:strerror", "//cuttlefish/posix:symlink", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel index 4b468a39492..7581dffed69 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel @@ -385,6 +385,7 @@ cf_cc_library( "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/log_names", "//cuttlefish/host/libs/metrics:device_metrics_orchestration", + "//cuttlefish/posix:remove", "//cuttlefish/posix:symlink", "//cuttlefish/process:command", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp index 8db76815af6..315f5a20417 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp @@ -66,6 +66,7 @@ #include "cuttlefish/host/commands/cvd/instances/local_instance_group.h" #include "cuttlefish/host/commands/cvd/utils/common.h" #include "cuttlefish/posix/realpath.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/strerror.h" #include "cuttlefish/posix/symlink.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp index eca0e9505ab..c327a25bf95 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp @@ -76,6 +76,7 @@ #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/log_names/log_names.h" #include "cuttlefish/host/libs/metrics/device_metrics_orchestration.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/symlink.h" #include "cuttlefish/process/command.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/log_files.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/log_files.cpp index 93675dc7d61..2f109e847b1 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/log_files.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/log_files.cpp @@ -27,10 +27,10 @@ #include "absl/log/log.h" #include "absl/strings/match.h" -#include "cuttlefish/common/libs/utils/files.h" #include "cuttlefish/files/directory_contents.h" #include "cuttlefish/files/directory_exists.h" #include "cuttlefish/host/commands/cvd/utils/common.h" +#include "cuttlefish/posix/remove.h" namespace cuttlefish { namespace { diff --git a/base/cvd/cuttlefish/host/commands/cvd/fetch/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/fetch/BUILD.bazel index e8f814df419..16cd15e9a2b 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/fetch/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/fetch/BUILD.bazel @@ -198,6 +198,7 @@ cf_cc_library( "//cuttlefish/host/libs/web:build_api_zip", "//cuttlefish/host/libs/zip:zip_file", "//cuttlefish/host/libs/zip/libzip_cc:archive", + "//cuttlefish/posix:remove", "//cuttlefish/result", "//libbase", "@abseil-cpp//absl/strings", diff --git a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_context.cc b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_context.cc index 9b71a3a7a54..3cd689bd5ec 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_context.cc +++ b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_context.cc @@ -44,6 +44,7 @@ #include "cuttlefish/host/libs/web/build_api_zip.h" #include "cuttlefish/host/libs/zip/libzip_cc/archive.h" #include "cuttlefish/host/libs/zip/zip_file.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/result/result.h" namespace cuttlefish { diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/instances/BUILD.bazel index badab95e0c3..42bc6630e30 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/BUILD.bazel @@ -182,6 +182,7 @@ cf_cc_library( "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/metrics:device_metrics_orchestration", "//cuttlefish/host/libs/screen_recording_controls", + "//cuttlefish/posix:remove", "//cuttlefish/posix:symlink", "//cuttlefish/process:command", "//cuttlefish/process:managed_stdio", @@ -246,6 +247,7 @@ cf_cc_library( "//cuttlefish/host/commands/cvd/instances:run_cvd_proc_collector", "//cuttlefish/host/commands/cvd/utils", "//cuttlefish/host/libs/config:config_constants", + "//cuttlefish/posix:remove", "//cuttlefish/posix:strerror", "//cuttlefish/process:command", "//cuttlefish/process:managed_stdio", diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp index 7471b71ec6a..6cb8c08f311 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp @@ -41,6 +41,7 @@ #include "cuttlefish/host/commands/cvd/utils/common.h" #include "cuttlefish/host/libs/config/config_utils.h" #include "cuttlefish/host/libs/metrics/device_metrics_orchestration.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/symlink.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/lock/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/instances/lock/BUILD.bazel index ed8ff3f9ad3..e58fdd58892 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/lock/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/lock/BUILD.bazel @@ -25,6 +25,7 @@ cf_cc_library( "//cuttlefish/common/libs/utils:files", "//cuttlefish/files:directory_exists", "//cuttlefish/host/commands/cvd/utils:common", + "//cuttlefish/posix:remove", "//cuttlefish/posix:strerror", "//cuttlefish/result", "//libbase", diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/lock/instance_lock.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/lock/instance_lock.cpp index bb2d082679b..c96dccf9043 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/lock/instance_lock.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/lock/instance_lock.cpp @@ -24,6 +24,7 @@ #include #include "cuttlefish/common/libs/utils/files.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/strerror.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/stop.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/stop.cpp index c7c817f7f48..33e1a6327d9 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/stop.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/stop.cpp @@ -40,6 +40,7 @@ #include "cuttlefish/host/commands/cvd/instances/run_cvd_proc_collector.h" #include "cuttlefish/host/commands/cvd/utils/common.h" #include "cuttlefish/host/libs/config/config_constants.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/strerror.h" #include "cuttlefish/process/command.h" #include "cuttlefish/process/managed_stdio.h" diff --git a/base/cvd/cuttlefish/host/commands/host_bugreport/BUILD.bazel b/base/cvd/cuttlefish/host/commands/host_bugreport/BUILD.bazel index 9c02f72d466..f42ccc99e53 100644 --- a/base/cvd/cuttlefish/host/commands/host_bugreport/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/host_bugreport/BUILD.bazel @@ -11,7 +11,6 @@ cf_cc_binary( include_cleaner_enabled = False, deps = [ "//cuttlefish/common/libs/utils:environment", - "//cuttlefish/common/libs/utils:files", "//cuttlefish/common/libs/utils:tee_logging", "//cuttlefish/files:directory_contents", "//cuttlefish/files:directory_exists", @@ -19,6 +18,7 @@ cf_cc_binary( "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/log_names", "//cuttlefish/host/libs/zip:zip_file", + "//cuttlefish/posix:remove", "//cuttlefish/posix:strerror", "//cuttlefish/process:command", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/host/commands/host_bugreport/main.cc b/base/cvd/cuttlefish/host/commands/host_bugreport/main.cc index 0cf580bd812..ba3be9cc2d2 100644 --- a/base/cvd/cuttlefish/host/commands/host_bugreport/main.cc +++ b/base/cvd/cuttlefish/host/commands/host_bugreport/main.cc @@ -23,7 +23,6 @@ #include "gflags/gflags.h" #include "cuttlefish/common/libs/utils/environment.h" -#include "cuttlefish/common/libs/utils/files.h" #include "cuttlefish/common/libs/utils/known_paths.h" #include "cuttlefish/common/libs/utils/tee_logging.h" #include "cuttlefish/files/directory_contents.h" @@ -32,6 +31,7 @@ #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/log_names/log_names.h" #include "cuttlefish/host/libs/zip/zip_file.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/strerror.h" #include "cuttlefish/process/command.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel b/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel index 3d6d8ebbb6b..e190b370b1a 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel @@ -153,6 +153,7 @@ cf_cc_library( "//cuttlefish/host/libs/feature:inject", "//cuttlefish/host/libs/process_monitor", "//cuttlefish/host/libs/vm_manager", + "//cuttlefish/posix:remove", "//cuttlefish/posix:strerror", "//cuttlefish/process:command", "//cuttlefish/process:execute", diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl.cpp b/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl.cpp index e1d442036db..e35a2ac24b9 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl.cpp +++ b/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl.cpp @@ -49,6 +49,7 @@ #include "cuttlefish/host/libs/config/vmm_mode.h" #include "cuttlefish/host/libs/feature/command_source.h" #include "cuttlefish/host/libs/process_monitor/process_monitor.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/strerror.h" #include "cuttlefish/process/command.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/libs/command_util/BUILD.bazel b/base/cvd/cuttlefish/host/libs/command_util/BUILD.bazel index 3d8ef70ac22..c739972eb8f 100644 --- a/base/cvd/cuttlefish/host/libs/command_util/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/command_util/BUILD.bazel @@ -43,6 +43,7 @@ cf_cc_library( "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/posix:readlink", "//cuttlefish/posix:realpath", + "//cuttlefish/posix:remove", "//cuttlefish/posix:strerror", "//cuttlefish/posix:symlink", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/host/libs/command_util/snapshot_utils.cc b/base/cvd/cuttlefish/host/libs/command_util/snapshot_utils.cc index de9f7f4c4e3..0deafaabb84 100644 --- a/base/cvd/cuttlefish/host/libs/command_util/snapshot_utils.cc +++ b/base/cvd/cuttlefish/host/libs/command_util/snapshot_utils.cc @@ -37,6 +37,7 @@ #include "cuttlefish/files/file_exists.h" #include "cuttlefish/posix/readlink.h" #include "cuttlefish/posix/realpath.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/posix/symlink.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/libs/config/BUILD.bazel b/base/cvd/cuttlefish/host/libs/config/BUILD.bazel index c2004bb71b6..817bd7093b6 100644 --- a/base/cvd/cuttlefish/host/libs/config/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/config/BUILD.bazel @@ -170,6 +170,7 @@ cf_cc_library( "//cuttlefish/host/libs/config:openwrt_args", "//cuttlefish/host/libs/config/esp:make_fat_image", "//cuttlefish/host/libs/image_aggregator:mbr", + "//cuttlefish/posix:remove", "//cuttlefish/process:command", "//cuttlefish/process:execute", "//cuttlefish/process:managed_stdio", diff --git a/base/cvd/cuttlefish/host/libs/config/data_image.cpp b/base/cvd/cuttlefish/host/libs/config/data_image.cpp index 6047b4d4349..c38c187540d 100644 --- a/base/cvd/cuttlefish/host/libs/config/data_image.cpp +++ b/base/cvd/cuttlefish/host/libs/config/data_image.cpp @@ -40,6 +40,7 @@ #include "cuttlefish/host/libs/config/esp/make_fat_image.h" #include "cuttlefish/host/libs/config/openwrt_args.h" #include "cuttlefish/host/libs/image_aggregator/mbr.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/process/command.h" #include "cuttlefish/process/execute.h" #include "cuttlefish/process/managed_stdio.h" diff --git a/base/cvd/cuttlefish/host/libs/web/cas/BUILD.bazel b/base/cvd/cuttlefish/host/libs/web/cas/BUILD.bazel index 9005a314df7..143ded4f532 100644 --- a/base/cvd/cuttlefish/host/libs/web/cas/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/web/cas/BUILD.bazel @@ -16,6 +16,7 @@ cf_cc_library( "//cuttlefish/files:file_exists", "//cuttlefish/host/libs/web:android_build", "//cuttlefish/host/libs/web/cas:cas_flags", + "//cuttlefish/posix:remove", "//cuttlefish/process:command", "//cuttlefish/process:managed_stdio", "//cuttlefish/result", @@ -34,6 +35,7 @@ cf_cc_test( "//cuttlefish/host/libs/web:android_build", "//cuttlefish/host/libs/web/cas:cas_downloader", "//cuttlefish/host/libs/web/cas:cas_flags", + "//cuttlefish/posix:remove", "//cuttlefish/result", "//cuttlefish/result:result_matchers", "//libbase", diff --git a/base/cvd/cuttlefish/host/libs/web/cas/cas_downloader.cpp b/base/cvd/cuttlefish/host/libs/web/cas/cas_downloader.cpp index 4312e749dfe..3ad4b877896 100644 --- a/base/cvd/cuttlefish/host/libs/web/cas/cas_downloader.cpp +++ b/base/cvd/cuttlefish/host/libs/web/cas/cas_downloader.cpp @@ -39,6 +39,7 @@ #include "cuttlefish/files/file_exists.h" #include "cuttlefish/host/libs/web/android_build.h" #include "cuttlefish/host/libs/web/cas/cas_flags.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/process/command.h" #include "cuttlefish/process/managed_stdio.h" #include "cuttlefish/result/result.h" diff --git a/base/cvd/cuttlefish/host/libs/web/cas/cas_downloader_test.cpp b/base/cvd/cuttlefish/host/libs/web/cas/cas_downloader_test.cpp index 9535634263d..af564421922 100644 --- a/base/cvd/cuttlefish/host/libs/web/cas/cas_downloader_test.cpp +++ b/base/cvd/cuttlefish/host/libs/web/cas/cas_downloader_test.cpp @@ -36,6 +36,7 @@ #include "cuttlefish/files/file_exists.h" #include "cuttlefish/host/libs/web/android_build.h" #include "cuttlefish/host/libs/web/cas/cas_flags.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/result/result.h" #include "cuttlefish/result/result_matchers.h" diff --git a/base/cvd/cuttlefish/host/libs/web/http_client/BUILD.bazel b/base/cvd/cuttlefish/host/libs/web/http_client/BUILD.bazel index a0fa79a4736..fe8cf878edb 100644 --- a/base/cvd/cuttlefish/host/libs/web/http_client/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/web/http_client/BUILD.bazel @@ -69,6 +69,7 @@ cf_cc_library( "//cuttlefish/common/libs/fs:shared_fd_stream", "//cuttlefish/common/libs/utils:files", "//cuttlefish/host/libs/web/http_client", + "//cuttlefish/posix:remove", "//cuttlefish/result", "@abseil-cpp//absl/log", ], diff --git a/base/cvd/cuttlefish/host/libs/web/http_client/http_file.cc b/base/cvd/cuttlefish/host/libs/web/http_client/http_file.cc index 5787f430985..5f2a0b4f086 100644 --- a/base/cvd/cuttlefish/host/libs/web/http_client/http_file.cc +++ b/base/cvd/cuttlefish/host/libs/web/http_client/http_file.cc @@ -29,6 +29,7 @@ #include "cuttlefish/common/libs/fs/shared_fd_stream.h" #include "cuttlefish/common/libs/utils/files.h" #include "cuttlefish/host/libs/web/http_client/http_client.h" +#include "cuttlefish/posix/remove.h" #include "cuttlefish/result/result.h" namespace cuttlefish { diff --git a/base/cvd/cuttlefish/posix/BUILD.bazel b/base/cvd/cuttlefish/posix/BUILD.bazel index 88425388e87..cd2b8fe34e1 100644 --- a/base/cvd/cuttlefish/posix/BUILD.bazel +++ b/base/cvd/cuttlefish/posix/BUILD.bazel @@ -53,3 +53,15 @@ cf_cc_library( "//cuttlefish/result:result_type", ], ) + +cf_cc_library( + name = "remove", + srcs = ["remove.cc"], + hdrs = ["remove.h"], + deps = [ + "//cuttlefish/posix:strerror", + "//cuttlefish/result:expect", + "//cuttlefish/result:result_type", + "@abseil-cpp//absl/log", + ], +) diff --git a/base/cvd/cuttlefish/posix/remove.cc b/base/cvd/cuttlefish/posix/remove.cc new file mode 100644 index 00000000000..f768f87b856 --- /dev/null +++ b/base/cvd/cuttlefish/posix/remove.cc @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cuttlefish/posix/remove.h" + +#include +#include + +#include + +#include "absl/log/log.h" + +#include "cuttlefish/posix/strerror.h" +#include "cuttlefish/result/expect.h" +#include "cuttlefish/result/result_type.h" + +namespace cuttlefish { + +Result RemoveFile(const std::string& file) { + VLOG(0) << "Removing file " << file; + if (remove(file.c_str()) != 0) { + return CF_ERRF("Failed to remove file '{}' : {}", file, StrError(errno)); + } + return {}; +} + +} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/posix/remove.h b/base/cvd/cuttlefish/posix/remove.h new file mode 100644 index 00000000000..fd3b383f71e --- /dev/null +++ b/base/cvd/cuttlefish/posix/remove.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include + +#include "cuttlefish/result/result_type.h" + +namespace cuttlefish { + +Result RemoveFile(const std::string& file); + +} // namespace cuttlefish