summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Applications/CrashReporter/main.cpp2
-rw-r--r--Userland/Applications/SpaceAnalyzer/main.cpp2
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.cpp2
-rw-r--r--Userland/DevTools/HackStudio/ProjectBuilder.cpp2
-rw-r--r--Userland/Libraries/LibCore/File.cpp15
-rw-r--r--Userland/Libraries/LibCore/File.h2
-rw-r--r--Userland/Libraries/LibCore/TempFile.cpp2
-rw-r--r--Userland/Utilities/headless-browser.cpp2
-rw-r--r--Userland/Utilities/rm.cpp11
-rw-r--r--Userland/Utilities/unzip.cpp2
10 files changed, 22 insertions, 20 deletions
diff --git a/Userland/Applications/CrashReporter/main.cpp b/Userland/Applications/CrashReporter/main.cpp
index ae21f397ce..60783c89fd 100644
--- a/Userland/Applications/CrashReporter/main.cpp
+++ b/Userland/Applications/CrashReporter/main.cpp
@@ -135,7 +135,7 @@ static TitleAndText build_cpu_registers(const ELF::Core::ThreadInfo& thread_info
static void unlink_coredump(StringView const& coredump_path)
{
- if (Core::File::remove(coredump_path, Core::File::RecursionMode::Disallowed, false).is_error())
+ if (Core::File::remove(coredump_path, Core::File::RecursionMode::Disallowed).is_error())
dbgln("Failed deleting coredump file");
}
diff --git a/Userland/Applications/SpaceAnalyzer/main.cpp b/Userland/Applications/SpaceAnalyzer/main.cpp
index 294e52d42a..8882fe845f 100644
--- a/Userland/Applications/SpaceAnalyzer/main.cpp
+++ b/Userland/Applications/SpaceAnalyzer/main.cpp
@@ -364,7 +364,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
while (try_again) {
try_again = false;
- auto deletion_result = Core::File::remove(selected_node_path, Core::File::RecursionMode::Allowed, true);
+ auto deletion_result = Core::File::remove(selected_node_path, Core::File::RecursionMode::Allowed);
if (deletion_result.is_error()) {
auto retry_message_result = GUI::MessageBox::show(window,
DeprecatedString::formatted("Failed to delete \"{}\": {}. Retry?",
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
index a97c6c6645..1d15bd3d4a 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
@@ -681,7 +681,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
}
bool is_directory = S_ISDIR(st.st_mode);
- if (auto result = Core::File::remove(file, Core::File::RecursionMode::Allowed, false); result.is_error()) {
+ if (auto result = Core::File::remove(file, Core::File::RecursionMode::Allowed); result.is_error()) {
auto& error = result.error();
if (is_directory) {
GUI::MessageBox::show(window(),
diff --git a/Userland/DevTools/HackStudio/ProjectBuilder.cpp b/Userland/DevTools/HackStudio/ProjectBuilder.cpp
index 2c63b20f19..71089a49a4 100644
--- a/Userland/DevTools/HackStudio/ProjectBuilder.cpp
+++ b/Userland/DevTools/HackStudio/ProjectBuilder.cpp
@@ -133,7 +133,7 @@ ErrorOr<void> ProjectBuilder::initialize_build_directory()
auto cmake_file_path = LexicalPath::join(build_directory(), "CMakeLists.txt"sv).string();
if (Core::File::exists(cmake_file_path))
- MUST(Core::File::remove(cmake_file_path, Core::File::RecursionMode::Disallowed, false));
+ MUST(Core::File::remove(cmake_file_path, Core::File::RecursionMode::Disallowed));
auto cmake_file = TRY(Core::Stream::File::open(cmake_file_path, Core::Stream::OpenMode::Write));
TRY(cmake_file->write_entire_buffer(generate_cmake_file_content().bytes()));
diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp
index b0337d4a75..e74752ca9b 100644
--- a/Userland/Libraries/LibCore/File.cpp
+++ b/Userland/Libraries/LibCore/File.cpp
@@ -549,14 +549,11 @@ ErrorOr<void> File::link_file(DeprecatedString const& dst_path, DeprecatedString
return {};
}
-ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode, bool force)
+ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode)
{
struct stat path_stat;
- if (lstat(path.characters(), &path_stat) < 0) {
- if (!force)
- return Error::from_errno(errno);
- return {};
- }
+ if (lstat(path.characters(), &path_stat) < 0)
+ return Error::from_errno(errno);
if (S_ISDIR(path_stat.st_mode) && mode == RecursionMode::Allowed) {
auto di = DirIterator(path, DirIterator::SkipParentAndBaseDir);
@@ -564,15 +561,15 @@ ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode, boo
return Error::from_errno(di.error());
while (di.has_next()) {
- auto result = remove(di.next_full_path(), RecursionMode::Allowed, true);
+ auto result = remove(di.next_full_path(), RecursionMode::Allowed);
if (result.is_error())
return result.error();
}
- if (rmdir(path.characters()) < 0 && !force)
+ if (rmdir(path.characters()) < 0)
return Error::from_errno(errno);
} else {
- if (unlink(path.characters()) < 0 && !force)
+ if (unlink(path.characters()) < 0)
return Error::from_errno(errno);
}
diff --git a/Userland/Libraries/LibCore/File.h b/Userland/Libraries/LibCore/File.h
index b3d115bc80..92cdd7d7dd 100644
--- a/Userland/Libraries/LibCore/File.h
+++ b/Userland/Libraries/LibCore/File.h
@@ -93,7 +93,7 @@ public:
static ErrorOr<DeprecatedString> read_link(DeprecatedString const& link_path);
static ErrorOr<void> link_file(DeprecatedString const& dst_path, DeprecatedString const& src_path);
- static ErrorOr<void> remove(DeprecatedString const& path, RecursionMode, bool force);
+ static ErrorOr<void> remove(DeprecatedString const& path, RecursionMode);
virtual bool open(OpenMode) override;
diff --git a/Userland/Libraries/LibCore/TempFile.cpp b/Userland/Libraries/LibCore/TempFile.cpp
index ae2a7dbf63..e6740a3c5e 100644
--- a/Userland/Libraries/LibCore/TempFile.cpp
+++ b/Userland/Libraries/LibCore/TempFile.cpp
@@ -49,7 +49,7 @@ TempFile::~TempFile()
if (m_type == Type::Directory)
recursion_allowed = File::RecursionMode::Allowed;
- auto rc = File::remove(m_path.characters(), recursion_allowed, false);
+ auto rc = File::remove(m_path.characters(), recursion_allowed);
if (rc.is_error()) {
warnln("File::remove failed: {}", rc.error().string_literal());
}
diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp
index 82aaeae03f..436f3c4a9e 100644
--- a/Userland/Utilities/headless-browser.cpp
+++ b/Userland/Utilities/headless-browser.cpp
@@ -687,7 +687,7 @@ static void load_page_for_screenshot_and_exit(HeadlessBrowserPageClient& page_cl
dbgln("Saving to {}", output_file_path);
if (Core::File::exists(output_file_path))
- MUST(Core::File::remove(output_file_path, Core::File::RecursionMode::Disallowed, true));
+ MUST(Core::File::remove(output_file_path, Core::File::RecursionMode::Disallowed));
auto output_file = MUST(Core::Stream::File::open(output_file_path, Core::Stream::OpenMode::Write));
diff --git a/Userland/Utilities/rm.cpp b/Userland/Utilities/rm.cpp
index dd05c0719d..01f7b2be85 100644
--- a/Userland/Utilities/rm.cpp
+++ b/Userland/Utilities/rm.cpp
@@ -25,7 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Core::ArgsParser args_parser;
args_parser.add_option(recursive, "Delete directories recursively", "recursive", 'r');
- args_parser.add_option(force, "Force", "force", 'f');
+ args_parser.add_option(force, "Ignore nonexistent files", "force", 'f');
args_parser.add_option(verbose, "Verbose", "verbose", 'v');
args_parser.add_option(no_preserve_root, "Do not consider '/' specially", "no-preserve-root", 0);
args_parser.add_positional_argument(paths, "Path(s) to remove", "path", Core::ArgsParser::Required::No);
@@ -43,10 +43,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
continue;
}
- auto result = Core::File::remove(path, recursive ? Core::File::RecursionMode::Allowed : Core::File::RecursionMode::Disallowed, force);
+ auto result = Core::File::remove(path, recursive ? Core::File::RecursionMode::Allowed : Core::File::RecursionMode::Disallowed);
if (result.is_error()) {
- warnln("rm: cannot remove '{}': {}", path, static_cast<Error const&>(result.error()));
+ auto error = result.error();
+
+ if (force && error.is_errno() && error.code() == ENOENT)
+ continue;
+
+ warnln("rm: cannot remove '{}': {}", path, error);
had_errors = true;
}
diff --git a/Userland/Utilities/unzip.cpp b/Userland/Utilities/unzip.cpp
index cfb206441b..c940b2453e 100644
--- a/Userland/Utilities/unzip.cpp
+++ b/Userland/Utilities/unzip.cpp
@@ -76,7 +76,7 @@ static bool unpack_zip_member(Archive::ZipMember zip_member, bool quiet)
if (checksum.digest() != zip_member.crc32) {
warnln("Failed decompressing file {}: CRC32 mismatch", zip_member.name);
- MUST(new_file->remove(zip_member.name, Core::File::RecursionMode::Disallowed, true));
+ MUST(Core::File::remove(zip_member.name, Core::File::RecursionMode::Disallowed));
return false;
}