diff --git a/Userland/Applications/CrashReporter/main.cpp b/Userland/Applications/CrashReporter/main.cpp index 60783c89fd..35116f7607 100644 --- a/Userland/Applications/CrashReporter/main.cpp +++ b/Userland/Applications/CrashReporter/main.cpp @@ -133,7 +133,7 @@ static TitleAndText build_cpu_registers(const ELF::Core::ThreadInfo& thread_info }; } -static void unlink_coredump(StringView const& coredump_path) +static void unlink_coredump(StringView coredump_path) { if (Core::File::remove(coredump_path, Core::File::RecursionMode::Disallowed).is_error()) dbgln("Failed deleting coredump file"); diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp index e74752ca9b..ace8386cd0 100644 --- a/Userland/Libraries/LibCore/File.cpp +++ b/Userland/Libraries/LibCore/File.cpp @@ -549,11 +549,9 @@ ErrorOr File::link_file(DeprecatedString const& dst_path, DeprecatedString return {}; } -ErrorOr File::remove(DeprecatedString const& path, RecursionMode mode) +ErrorOr File::remove(StringView path, RecursionMode mode) { - struct stat path_stat; - if (lstat(path.characters(), &path_stat) < 0) - return Error::from_errno(errno); + auto path_stat = TRY(Core::System::lstat(path)); if (S_ISDIR(path_stat.st_mode) && mode == RecursionMode::Allowed) { auto di = DirIterator(path, DirIterator::SkipParentAndBaseDir); @@ -561,16 +559,12 @@ ErrorOr File::remove(DeprecatedString const& path, RecursionMode mode) return Error::from_errno(di.error()); while (di.has_next()) { - auto result = remove(di.next_full_path(), RecursionMode::Allowed); - if (result.is_error()) - return result.error(); + TRY(remove(di.next_full_path(), RecursionMode::Allowed)); } - if (rmdir(path.characters()) < 0) - return Error::from_errno(errno); + TRY(Core::System::rmdir(path)); } else { - if (unlink(path.characters()) < 0) - return Error::from_errno(errno); + TRY(Core::System::unlink(path)); } return {}; diff --git a/Userland/Libraries/LibCore/File.h b/Userland/Libraries/LibCore/File.h index 92cdd7d7dd..36022cfabf 100644 --- a/Userland/Libraries/LibCore/File.h +++ b/Userland/Libraries/LibCore/File.h @@ -93,7 +93,7 @@ public: static ErrorOr read_link(DeprecatedString const& link_path); static ErrorOr link_file(DeprecatedString const& dst_path, DeprecatedString const& src_path); - static ErrorOr remove(DeprecatedString const& path, RecursionMode); + static ErrorOr remove(StringView path, RecursionMode); virtual bool open(OpenMode) override; diff --git a/Userland/Libraries/LibCore/TempFile.cpp b/Userland/Libraries/LibCore/TempFile.cpp index e6740a3c5e..e13f5ccec6 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); + auto rc = File::remove(m_path, recursion_allowed); if (rc.is_error()) { warnln("File::remove failed: {}", rc.error().string_literal()); }