From 3cc0283eac8fc2985ea606b82a56d755a8c1eeb8 Mon Sep 17 00:00:00 2001 From: Timothy Date: Sat, 10 Jul 2021 01:41:07 +1000 Subject: [PATCH] LibCore: Convert File to east-const style --- Userland/Libraries/LibCore/File.cpp | 26 +++++++++++++------------- Userland/Libraries/LibCore/File.h | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp index 319d094ce22..7e8c4210f46 100644 --- a/Userland/Libraries/LibCore/File.cpp +++ b/Userland/Libraries/LibCore/File.cpp @@ -106,7 +106,7 @@ bool File::is_device() const return S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode); } -bool File::is_device(const String& filename) +bool File::is_device(String const& filename) { struct stat st; if (stat(filename.characters(), &st) < 0) @@ -122,7 +122,7 @@ bool File::is_directory() const return S_ISDIR(stat.st_mode); } -bool File::is_directory(const String& filename) +bool File::is_directory(String const& filename) { struct stat st; if (stat(filename.characters(), &st) < 0) @@ -138,7 +138,7 @@ bool File::is_link() const return S_ISLNK(stat.st_mode); } -bool File::is_link(const String& filename) +bool File::is_link(String const& filename) { struct stat st; if (lstat(filename.characters(), &st) < 0) @@ -146,13 +146,13 @@ bool File::is_link(const String& filename) return S_ISLNK(st.st_mode); } -bool File::exists(const String& filename) +bool File::exists(String const& filename) { struct stat st; return stat(filename.characters(), &st) == 0; } -String File::real_path_for(const String& filename) +String File::real_path_for(String const& filename) { if (filename.is_null()) return {}; @@ -162,7 +162,7 @@ String File::real_path_for(const String& filename) return real_path; } -bool File::ensure_parent_directories(const String& path) +bool File::ensure_parent_directories(String const& path) { VERIFY(path.starts_with("/")); @@ -172,7 +172,7 @@ bool File::ensure_parent_directories(const String& path) char* parent_buffer = strdup(path.characters()); ScopeGuard free_buffer = [parent_buffer] { free(parent_buffer); }; - const char* parent = dirname(parent_buffer); + char const* parent = dirname(parent_buffer); int rc = mkdir(parent, 0755); saved_errno = errno; @@ -313,7 +313,7 @@ NonnullRefPtr File::standard_error() return *stderr_file; } -static String get_duplicate_name(const String& path, int duplicate_count) +static String get_duplicate_name(String const& path, int duplicate_count) { if (duplicate_count == 0) { return path; @@ -338,7 +338,7 @@ static String get_duplicate_name(const String& path, int duplicate_count) return duplicated_name.build(); } -Result File::copy_file_or_directory(const String& dst_path, const String& src_path, RecursionMode recursion_mode, LinkMode link_mode, AddDuplicateFileMarker add_duplicate_file_marker) +Result File::copy_file_or_directory(String const& dst_path, String const& src_path, RecursionMode recursion_mode, LinkMode link_mode, AddDuplicateFileMarker add_duplicate_file_marker) { if (add_duplicate_file_marker == AddDuplicateFileMarker::Yes) { int duplicate_count = 0; @@ -376,7 +376,7 @@ Result File::copy_file_or_directory(const String& dst_pat return copy_file(dst_path, src_stat, source); } -Result File::copy_file(const String& dst_path, const struct stat& src_stat, File& source) +Result File::copy_file(String const& dst_path, struct stat const& src_stat, File& source) { int dst_fd = creat(dst_path.characters(), 0666); if (dst_fd < 0) { @@ -426,7 +426,7 @@ Result File::copy_file(const String& dst_path, const stru return {}; } -Result File::copy_directory(const String& dst_path, const String& src_path, const struct stat& src_stat, LinkMode link) +Result File::copy_directory(String const& dst_path, String const& src_path, struct stat const& src_stat, LinkMode link) { if (mkdir(dst_path.characters(), 0755) < 0) return CopyError { OSError(errno), false }; @@ -461,7 +461,7 @@ Result File::copy_directory(const String& dst_path, const return {}; } -Result File::link_file(const String& dst_path, const String& src_path) +Result File::link_file(String const& dst_path, String const& src_path) { int duplicate_count = 0; while (access(get_duplicate_name(dst_path, duplicate_count).characters(), F_OK) == 0) { @@ -478,7 +478,7 @@ Result File::link_file(const String& dst_path, const String& src_ return {}; } -Result File::remove(const String& path, RecursionMode mode, bool force) +Result File::remove(String const& path, RecursionMode mode, bool force) { struct stat path_stat; if (lstat(path.characters(), &path_stat) < 0) { diff --git a/Userland/Libraries/LibCore/File.h b/Userland/Libraries/LibCore/File.h index 419ec4b416f..a8649a20b05 100644 --- a/Userland/Libraries/LibCore/File.h +++ b/Userland/Libraries/LibCore/File.h @@ -25,16 +25,16 @@ public: void set_filename(const String filename) { m_filename = move(filename); } bool is_directory() const; - static bool is_directory(const String& filename); + static bool is_directory(String const& filename); bool is_device() const; - static bool is_device(const String& filename); + static bool is_device(String const& filename); bool is_link() const; - static bool is_link(const String& filename); + static bool is_link(String const& filename); - static bool exists(const String& filename); - static bool ensure_parent_directories(const String& path); + static bool exists(String const& filename); + static bool ensure_parent_directories(String const& path); static String current_working_directory(); static String absolute_path(String const& path); @@ -58,19 +58,19 @@ public: bool tried_recursing; }; - static Result copy_file(const String& dst_path, const struct stat& src_stat, File& source); - static Result copy_directory(const String& dst_path, const String& src_path, const struct stat& src_stat, LinkMode = LinkMode::Disallowed); - static Result copy_file_or_directory(const String& dst_path, const String& src_path, RecursionMode = RecursionMode::Allowed, LinkMode = LinkMode::Disallowed, AddDuplicateFileMarker = AddDuplicateFileMarker::Yes); + static Result copy_file(String const& dst_path, struct stat const& src_stat, File& source); + static Result copy_directory(String const& dst_path, String const& src_path, struct stat const& src_stat, LinkMode = LinkMode::Disallowed); + static Result copy_file_or_directory(String const& dst_path, String const& src_path, RecursionMode = RecursionMode::Allowed, LinkMode = LinkMode::Disallowed, AddDuplicateFileMarker = AddDuplicateFileMarker::Yes); - static String real_path_for(const String& filename); + static String real_path_for(String const& filename); static String read_link(String const& link_path); - static Result link_file(const String& dst_path, const String& src_path); + static Result link_file(String const& dst_path, String const& src_path); struct RemoveError { String file; OSError error_code; }; - static Result remove(const String& path, RecursionMode, bool force); + static Result remove(String const& path, RecursionMode, bool force); virtual bool open(OpenMode) override;