mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibCore: Use a StringView for the file path in File::remove
This allows us to use our nice syscall wrappers, avoids some accidental string copying, and starts to unlink us from the old DeprecatedString.
This commit is contained in:
parent
9805f73704
commit
8455d58a44
4 changed files with 8 additions and 14 deletions
|
@ -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())
|
if (Core::File::remove(coredump_path, Core::File::RecursionMode::Disallowed).is_error())
|
||||||
dbgln("Failed deleting coredump file");
|
dbgln("Failed deleting coredump file");
|
||||||
|
|
|
@ -549,11 +549,9 @@ ErrorOr<void> File::link_file(DeprecatedString const& dst_path, DeprecatedString
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode)
|
ErrorOr<void> File::remove(StringView path, RecursionMode mode)
|
||||||
{
|
{
|
||||||
struct stat path_stat;
|
auto path_stat = TRY(Core::System::lstat(path));
|
||||||
if (lstat(path.characters(), &path_stat) < 0)
|
|
||||||
return Error::from_errno(errno);
|
|
||||||
|
|
||||||
if (S_ISDIR(path_stat.st_mode) && mode == RecursionMode::Allowed) {
|
if (S_ISDIR(path_stat.st_mode) && mode == RecursionMode::Allowed) {
|
||||||
auto di = DirIterator(path, DirIterator::SkipParentAndBaseDir);
|
auto di = DirIterator(path, DirIterator::SkipParentAndBaseDir);
|
||||||
|
@ -561,16 +559,12 @@ ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode)
|
||||||
return Error::from_errno(di.error());
|
return Error::from_errno(di.error());
|
||||||
|
|
||||||
while (di.has_next()) {
|
while (di.has_next()) {
|
||||||
auto result = remove(di.next_full_path(), RecursionMode::Allowed);
|
TRY(remove(di.next_full_path(), RecursionMode::Allowed));
|
||||||
if (result.is_error())
|
|
||||||
return result.error();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rmdir(path.characters()) < 0)
|
TRY(Core::System::rmdir(path));
|
||||||
return Error::from_errno(errno);
|
|
||||||
} else {
|
} else {
|
||||||
if (unlink(path.characters()) < 0)
|
TRY(Core::System::unlink(path));
|
||||||
return Error::from_errno(errno);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -93,7 +93,7 @@ public:
|
||||||
static ErrorOr<DeprecatedString> read_link(DeprecatedString const& link_path);
|
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> link_file(DeprecatedString const& dst_path, DeprecatedString const& src_path);
|
||||||
|
|
||||||
static ErrorOr<void> remove(DeprecatedString const& path, RecursionMode);
|
static ErrorOr<void> remove(StringView path, RecursionMode);
|
||||||
|
|
||||||
virtual bool open(OpenMode) override;
|
virtual bool open(OpenMode) override;
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ TempFile::~TempFile()
|
||||||
if (m_type == Type::Directory)
|
if (m_type == Type::Directory)
|
||||||
recursion_allowed = File::RecursionMode::Allowed;
|
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()) {
|
if (rc.is_error()) {
|
||||||
warnln("File::remove failed: {}", rc.error().string_literal());
|
warnln("File::remove failed: {}", rc.error().string_literal());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue