mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:57:35 +00:00
FileManager: Replicate permissions on directory copy (#1437)
When copying files, the original file permissions are applied to the copy. However, this was not done with directories. This should do it.
This commit is contained in:
parent
2623bd711b
commit
238afd37cf
2 changed files with 10 additions and 3 deletions
|
@ -93,12 +93,12 @@ bool copy_file_or_directory(const String& src_path, const String& dst_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISDIR(src_stat.st_mode)) {
|
if (S_ISDIR(src_stat.st_mode)) {
|
||||||
return copy_directory(src_path, dst_path);
|
return copy_directory(src_path, dst_path, src_stat);
|
||||||
}
|
}
|
||||||
return copy_file(src_path, dst_path, src_stat, src_fd);
|
return copy_file(src_path, dst_path, src_stat, src_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool copy_directory(const String& src_path, const String& dst_path)
|
bool copy_directory(const String& src_path, const String& dst_path, const struct stat& src_stat)
|
||||||
{
|
{
|
||||||
int rc = mkdir(dst_path.characters(), 0755);
|
int rc = mkdir(dst_path.characters(), 0755);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
@ -117,6 +117,13 @@ bool copy_directory(const String& src_path, const String& dst_path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto my_umask = umask(0);
|
||||||
|
umask(my_umask);
|
||||||
|
rc = chmod(dst_path.characters(), src_stat.st_mode & ~my_umask);
|
||||||
|
if (rc < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,6 @@ int delete_directory(String directory, String& file_that_caused_error);
|
||||||
bool copy_file_or_directory(const String& src_path, const String& dst_path);
|
bool copy_file_or_directory(const String& src_path, const String& dst_path);
|
||||||
String get_duplicate_name(const String& path, int duplicate_count);
|
String get_duplicate_name(const String& path, int duplicate_count);
|
||||||
bool copy_file(const String& src_path, const String& dst_path, const struct stat& src_stat, int src_fd);
|
bool copy_file(const String& src_path, const String& dst_path, const struct stat& src_stat, int src_fd);
|
||||||
bool copy_directory(const String& src_path, const String& dst_path);
|
bool copy_directory(const String& src_path, const String& dst_path, const struct stat& src_stat);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue