Truly independent web browser
LibFileSystem: Remove unused directory copying functions
Andreas Kling97bb6adf3a21
diff --git a/Libraries/LibFileSystem/FileSystem.cpp b/Libraries/LibFileSystem/FileSystem.cppindex e6a919560c7..763f8d9f2ff 100644--- a/Libraries/LibFileSystem/FileSystem.cpp+++ b/Libraries/LibFileSystem/FileSystem.cpp@@ -196,22 +196,6 @@ bool is_link(int fd)return S_ISLNK(st.st_mode);}-static ErrorOr<ByteString> get_duplicate_file_name(StringView path)-{- int duplicate_count = 0;- LexicalPath lexical_path(path);- auto parent_path = LexicalPath::canonicalized_path(lexical_path.dirname());- auto basename = lexical_path.basename();- auto current_name = LexicalPath::join(parent_path, basename).string();-- while (exists(current_name)) {- ++duplicate_count;- current_name = LexicalPath::join(parent_path, ByteString::formatted("{} ({})", basename, duplicate_count)).string();- }-- return current_name;-}-ErrorOr<void> copy_file(StringView destination_path, StringView source_path, struct stat const& source_stat, Core::File& source, PreserveMode preserve_mode){auto destination_or_error = Core::File::open(destination_path, Core::File::OpenMode::Write, 0666);@@ -265,81 +249,6 @@ ErrorOr<void> copy_file(StringView destination_path, StringView source_path, strreturn {};}-ErrorOr<void> copy_directory(StringView destination_path, StringView source_path, struct stat const& source_stat, LinkMode link, PreserveMode preserve_mode)-{- TRY(Core::System::mkdir(destination_path, 0755));-- auto source_rp = TRY(real_path(source_path));- source_rp = ByteString::formatted("{}/", source_rp);-- auto destination_rp = TRY(real_path(destination_path));- destination_rp = ByteString::formatted("{}/", destination_rp);-- if (!destination_rp.is_empty() && destination_rp.starts_with(source_rp))- return Error::from_errno(EINVAL);-- Core::DirIterator di(source_path, Core::DirIterator::SkipParentAndBaseDir);- if (di.has_error())- return di.error();-- while (di.has_next()) {- auto filename = di.next_path();- TRY(copy_file_or_directory(- ByteString::formatted("{}/{}", destination_path, filename),- ByteString::formatted("{}/{}", source_path, filename),- RecursionMode::Allowed, link, AddDuplicateFileMarker::Yes, preserve_mode));- }-- auto my_umask = umask(0);- umask(my_umask);-- TRY(Core::System::chmod(destination_path, source_stat.st_mode & ~my_umask));-- if (has_flag(preserve_mode, PreserveMode::Ownership))- TRY(Core::System::chown(destination_path, source_stat.st_uid, source_stat.st_gid));-- if (has_flag(preserve_mode, PreserveMode::Timestamps)) {- struct timespec times[2] = {-# if defined(AK_OS_MACOS) || defined(AK_OS_IOS)- source_stat.st_atimespec,- source_stat.st_mtimespec,-# else- source_stat.st_atim,- source_stat.st_mtim,-# endif- };- TRY(Core::System::utimensat(AT_FDCWD, destination_path, times, 0));- }-- return {};-}--ErrorOr<void> copy_file_or_directory(StringView destination_path, StringView source_path, RecursionMode recursion_mode, LinkMode link_mode, AddDuplicateFileMarker add_duplicate_file_marker, PreserveMode preserve_mode)-{- ByteString final_destination_path;- if (add_duplicate_file_marker == AddDuplicateFileMarker::Yes)- final_destination_path = TRY(get_duplicate_file_name(destination_path));- else- final_destination_path = destination_path;-- auto source = TRY(Core::File::open(source_path, Core::File::OpenMode::Read));-- auto source_stat = TRY(Core::System::fstat(source->fd()));-- if (is_directory(source_path)) {- if (recursion_mode == RecursionMode::Disallowed) {- return Error::from_errno(EISDIR);- }-- return copy_directory(final_destination_path, source_path, source_stat, link_mode, preserve_mode);- }-- if (link_mode == LinkMode::Allowed)- return TRY(Core::System::link(source_path, final_destination_path));-- return copy_file(final_destination_path, source_path, source_stat, *source, preserve_mode);-}-ErrorOr<void> move_file(StringView destination_path, StringView source_path, PreserveMode preserve_mode){auto maybe_error = Core::System::rename(source_path, destination_path);diff --git a/Libraries/LibFileSystem/FileSystem.h b/Libraries/LibFileSystem/FileSystem.hindex c7ed508d6ff..2a31455ef51 100644--- a/Libraries/LibFileSystem/FileSystem.h+++ b/Libraries/LibFileSystem/FileSystem.h@@ -39,16 +39,6 @@ enum class RecursionMode {Disallowed};-enum class LinkMode {- Allowed,- Disallowed-};--enum class AddDuplicateFileMarker {- Yes,- No,-};-enum class PreserveMode {Nothing = 0,Permissions = (1 << 0),@@ -58,8 +48,6 @@ enum class PreserveMode {AK_ENUM_BITWISE_OPERATORS(PreserveMode);ErrorOr<void> copy_file(StringView destination_path, StringView source_path, struct stat const& source_stat, Core::File& source, PreserveMode = PreserveMode::Nothing);-ErrorOr<void> copy_directory(StringView destination_path, StringView source_path, struct stat const& source_stat, LinkMode = LinkMode::Disallowed, PreserveMode = PreserveMode::Nothing);-ErrorOr<void> copy_file_or_directory(StringView destination_path, StringView source_path, RecursionMode = RecursionMode::Allowed, LinkMode = LinkMode::Disallowed, AddDuplicateFileMarker = AddDuplicateFileMarker::Yes, PreserveMode = PreserveMode::Nothing);ErrorOr<void> move_file(StringView destination_path, StringView source_path, PreserveMode = PreserveMode::Nothing);// Renames a file within one file system, failing with EEXIST instead of replacing an existing destination. A file system// that cannot do that atomically gets a copy in a destination file created only if none exists. The file is at its