diff --git a/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel b/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel index 47f90d4b2b5..b8a052ada55 100644 --- a/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel +++ b/base/cvd/cuttlefish/common/libs/utils/BUILD.bazel @@ -122,6 +122,7 @@ cf_cc_library( "//cuttlefish/files:link_or_copy", "//cuttlefish/io:string", "//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 9c592aceb19..c8c2d8e5b89 100644 --- a/base/cvd/cuttlefish/common/libs/utils/files.cpp +++ b/base/cvd/cuttlefish/common/libs/utils/files.cpp @@ -60,6 +60,7 @@ #include "cuttlefish/files/link_or_copy.h" #include "cuttlefish/io/string.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" @@ -269,14 +270,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 f9e0c02547b..f83969cab56 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel @@ -84,6 +84,7 @@ cf_cc_binary( "//cuttlefish/host/libs/feature:inject", "//cuttlefish/host/libs/log_names", "//cuttlefish/io:string", + "//cuttlefish/posix:remove", "//cuttlefish/posix:symlink", "//cuttlefish/pretty:vector", "//cuttlefish/result", @@ -111,6 +112,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", @@ -144,6 +146,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 87f795c2a69..eaa3e173a29 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd.cc @@ -102,6 +102,7 @@ #include "cuttlefish/host/libs/feature/inject.h" #include "cuttlefish/host/libs/log_names/log_names.h" #include "cuttlefish/io/string.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 a2a016d14f1..96baad0397b 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel @@ -74,10 +74,10 @@ cf_cc_library( srcs = ["log_files.cpp"], hdrs = ["log_files.h"], 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", @@ -167,6 +167,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 a4380a7a470..7ad73bef830 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel @@ -387,6 +387,7 @@ cf_cc_library( "//cuttlefish/host/libs/log_names", "//cuttlefish/host/libs/metrics:device_metrics_orchestration", "//cuttlefish/io:string", + "//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 9c05cfd6b62..4082dfcad48 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp @@ -77,6 +77,7 @@ #include "cuttlefish/host/libs/log_names/log_names.h" #include "cuttlefish/host/libs/metrics/device_metrics_orchestration.h" #include "cuttlefish/io/string.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 45115e645aa..da902716ddb 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/log_files.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/log_files.cpp @@ -31,10 +31,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" #include "cuttlefish/result/result.h" namespace cuttlefish { 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 dd0a63ff5f9..fd6e5d09188 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 33c696230d8..58825b8c8c8 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/BUILD.bazel @@ -183,6 +183,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", @@ -247,6 +248,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 ccdda17fa6b..12a29a37d72 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel @@ -155,6 +155,7 @@ cf_cc_library( "//cuttlefish/host/libs/process_monitor", "//cuttlefish/host/libs/vm_manager", "//cuttlefish/io:string", + "//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 4c7632531f4..21de58f3ae0 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 @@ -50,6 +50,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 0ff8722d265..d809ce9dd1c 100644 --- a/base/cvd/cuttlefish/host/libs/command_util/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/command_util/BUILD.bazel @@ -42,6 +42,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 53aeb9ea22a..43497bca6b0 100644 --- a/base/cvd/cuttlefish/host/libs/command_util/snapshot_utils.cc +++ b/base/cvd/cuttlefish/host/libs/command_util/snapshot_utils.cc @@ -42,6 +42,7 @@ #include "cuttlefish/host/libs/config/cuttlefish_config.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 e7da7bdc88a..1ebda45f5a2 100644 --- a/base/cvd/cuttlefish/host/libs/config/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/config/BUILD.bazel @@ -162,6 +162,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 3d5b27a9546..d82a7e818e9 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