mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:17:45 +00:00
LibCore: Make copying permissions, ownership and timestamps combineable
This commit is contained in:
parent
a85b728768
commit
69e0b8dbb7
3 changed files with 19 additions and 6 deletions
|
@ -408,16 +408,18 @@ ErrorOr<void, File::CopyError> File::copy_file(String const& dst_path, struct st
|
|||
auto my_umask = umask(0);
|
||||
umask(my_umask);
|
||||
// NOTE: We don't copy the set-uid and set-gid bits unless requested.
|
||||
if (preserve_mode != PreserveMode::PermissionsOwnershipTimestamps)
|
||||
if (!has_flag(preserve_mode, PreserveMode::Permissions))
|
||||
my_umask |= 06000;
|
||||
|
||||
if (fchmod(dst_fd, src_stat.st_mode & ~my_umask) < 0)
|
||||
return CopyError { errno, false };
|
||||
|
||||
if (preserve_mode == PreserveMode::PermissionsOwnershipTimestamps) {
|
||||
if (has_flag(preserve_mode, PreserveMode::Ownership)) {
|
||||
if (fchown(dst_fd, src_stat.st_uid, src_stat.st_gid) < 0)
|
||||
return CopyError { errno, false };
|
||||
}
|
||||
|
||||
if (has_flag(preserve_mode, PreserveMode::Timestamps)) {
|
||||
// FIXME: Implement utimens() and use it here.
|
||||
struct utimbuf timbuf;
|
||||
timbuf.actime = src_stat.st_atime;
|
||||
|
@ -462,10 +464,12 @@ ErrorOr<void, File::CopyError> File::copy_directory(String const& dst_path, Stri
|
|||
if (chmod(dst_path.characters(), src_stat.st_mode & ~my_umask) < 0)
|
||||
return CopyError { errno, false };
|
||||
|
||||
if (preserve_mode == PreserveMode::PermissionsOwnershipTimestamps) {
|
||||
if (has_flag(preserve_mode, PreserveMode::Ownership)) {
|
||||
if (chown(dst_path.characters(), src_stat.st_uid, src_stat.st_gid) < 0)
|
||||
return CopyError { errno, false };
|
||||
}
|
||||
|
||||
if (has_flag(preserve_mode, PreserveMode::Timestamps)) {
|
||||
// FIXME: Implement utimens() and use it here.
|
||||
struct utimbuf timbuf;
|
||||
timbuf.actime = src_stat.st_atime;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue