1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:37:45 +00:00

LibCore: Convert File to east-const style

This commit is contained in:
Timothy 2021-07-10 01:41:07 +10:00 committed by Ali Mohammad Pur
parent 068802d58d
commit 3cc0283eac
2 changed files with 24 additions and 24 deletions

View file

@ -106,7 +106,7 @@ bool File::is_device() const
return S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode); 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; struct stat st;
if (stat(filename.characters(), &st) < 0) if (stat(filename.characters(), &st) < 0)
@ -122,7 +122,7 @@ bool File::is_directory() const
return S_ISDIR(stat.st_mode); return S_ISDIR(stat.st_mode);
} }
bool File::is_directory(const String& filename) bool File::is_directory(String const& filename)
{ {
struct stat st; struct stat st;
if (stat(filename.characters(), &st) < 0) if (stat(filename.characters(), &st) < 0)
@ -138,7 +138,7 @@ bool File::is_link() const
return S_ISLNK(stat.st_mode); return S_ISLNK(stat.st_mode);
} }
bool File::is_link(const String& filename) bool File::is_link(String const& filename)
{ {
struct stat st; struct stat st;
if (lstat(filename.characters(), &st) < 0) if (lstat(filename.characters(), &st) < 0)
@ -146,13 +146,13 @@ bool File::is_link(const String& filename)
return S_ISLNK(st.st_mode); return S_ISLNK(st.st_mode);
} }
bool File::exists(const String& filename) bool File::exists(String const& filename)
{ {
struct stat st; struct stat st;
return stat(filename.characters(), &st) == 0; 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()) if (filename.is_null())
return {}; return {};
@ -162,7 +162,7 @@ String File::real_path_for(const String& filename)
return real_path; return real_path;
} }
bool File::ensure_parent_directories(const String& path) bool File::ensure_parent_directories(String const& path)
{ {
VERIFY(path.starts_with("/")); VERIFY(path.starts_with("/"));
@ -172,7 +172,7 @@ bool File::ensure_parent_directories(const String& path)
char* parent_buffer = strdup(path.characters()); char* parent_buffer = strdup(path.characters());
ScopeGuard free_buffer = [parent_buffer] { free(parent_buffer); }; 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); int rc = mkdir(parent, 0755);
saved_errno = errno; saved_errno = errno;
@ -313,7 +313,7 @@ NonnullRefPtr<File> File::standard_error()
return *stderr_file; 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) { if (duplicate_count == 0) {
return path; return path;
@ -338,7 +338,7 @@ static String get_duplicate_name(const String& path, int duplicate_count)
return duplicated_name.build(); return duplicated_name.build();
} }
Result<void, File::CopyError> 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<void, File::CopyError> 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) { if (add_duplicate_file_marker == AddDuplicateFileMarker::Yes) {
int duplicate_count = 0; int duplicate_count = 0;
@ -376,7 +376,7 @@ Result<void, File::CopyError> File::copy_file_or_directory(const String& dst_pat
return copy_file(dst_path, src_stat, source); return copy_file(dst_path, src_stat, source);
} }
Result<void, File::CopyError> File::copy_file(const String& dst_path, const struct stat& src_stat, File& source) Result<void, File::CopyError> File::copy_file(String const& dst_path, struct stat const& src_stat, File& source)
{ {
int dst_fd = creat(dst_path.characters(), 0666); int dst_fd = creat(dst_path.characters(), 0666);
if (dst_fd < 0) { if (dst_fd < 0) {
@ -426,7 +426,7 @@ Result<void, File::CopyError> File::copy_file(const String& dst_path, const stru
return {}; return {};
} }
Result<void, File::CopyError> File::copy_directory(const String& dst_path, const String& src_path, const struct stat& src_stat, LinkMode link) Result<void, File::CopyError> 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) if (mkdir(dst_path.characters(), 0755) < 0)
return CopyError { OSError(errno), false }; return CopyError { OSError(errno), false };
@ -461,7 +461,7 @@ Result<void, File::CopyError> File::copy_directory(const String& dst_path, const
return {}; return {};
} }
Result<void, OSError> File::link_file(const String& dst_path, const String& src_path) Result<void, OSError> File::link_file(String const& dst_path, String const& src_path)
{ {
int duplicate_count = 0; int duplicate_count = 0;
while (access(get_duplicate_name(dst_path, duplicate_count).characters(), F_OK) == 0) { while (access(get_duplicate_name(dst_path, duplicate_count).characters(), F_OK) == 0) {
@ -478,7 +478,7 @@ Result<void, OSError> File::link_file(const String& dst_path, const String& src_
return {}; return {};
} }
Result<void, File::RemoveError> File::remove(const String& path, RecursionMode mode, bool force) Result<void, File::RemoveError> File::remove(String const& path, RecursionMode mode, bool force)
{ {
struct stat path_stat; struct stat path_stat;
if (lstat(path.characters(), &path_stat) < 0) { if (lstat(path.characters(), &path_stat) < 0) {

View file

@ -25,16 +25,16 @@ public:
void set_filename(const String filename) { m_filename = move(filename); } void set_filename(const String filename) { m_filename = move(filename); }
bool is_directory() const; bool is_directory() const;
static bool is_directory(const String& filename); static bool is_directory(String const& filename);
bool is_device() const; bool is_device() const;
static bool is_device(const String& filename); static bool is_device(String const& filename);
bool is_link() const; 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 exists(String const& filename);
static bool ensure_parent_directories(const String& path); static bool ensure_parent_directories(String const& path);
static String current_working_directory(); static String current_working_directory();
static String absolute_path(String const& path); static String absolute_path(String const& path);
@ -58,19 +58,19 @@ public:
bool tried_recursing; bool tried_recursing;
}; };
static Result<void, CopyError> copy_file(const String& dst_path, const struct stat& src_stat, File& source); static Result<void, CopyError> copy_file(String const& dst_path, struct stat const& src_stat, File& source);
static Result<void, CopyError> copy_directory(const String& dst_path, const String& src_path, const struct stat& src_stat, LinkMode = LinkMode::Disallowed); static Result<void, CopyError> copy_directory(String const& dst_path, String const& src_path, struct stat const& src_stat, LinkMode = LinkMode::Disallowed);
static Result<void, CopyError> copy_file_or_directory(const String& dst_path, const String& src_path, RecursionMode = RecursionMode::Allowed, LinkMode = LinkMode::Disallowed, AddDuplicateFileMarker = AddDuplicateFileMarker::Yes); static Result<void, CopyError> 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 String read_link(String const& link_path);
static Result<void, OSError> link_file(const String& dst_path, const String& src_path); static Result<void, OSError> link_file(String const& dst_path, String const& src_path);
struct RemoveError { struct RemoveError {
String file; String file;
OSError error_code; OSError error_code;
}; };
static Result<void, RemoveError> remove(const String& path, RecursionMode, bool force); static Result<void, RemoveError> remove(String const& path, RecursionMode, bool force);
virtual bool open(OpenMode) override; virtual bool open(OpenMode) override;