mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
Utilities: Implement -p flag for cp
This commit is contained in:
parent
8cc8d72619
commit
58cebf1b6f
1 changed files with 14 additions and 2 deletions
|
@ -12,12 +12,13 @@
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (pledge("stdio rpath wpath cpath fattr", nullptr) < 0) {
|
||||
if (pledge("stdio rpath wpath cpath fattr chown", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool link = false;
|
||||
bool preserve = false;
|
||||
bool recursion_allowed = false;
|
||||
bool verbose = false;
|
||||
Vector<String> sources;
|
||||
|
@ -25,6 +26,7 @@ int main(int argc, char** argv)
|
|||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(link, "Link files instead of copying", "link", 'l');
|
||||
args_parser.add_option(preserve, "Preserve time, UID/GID and file permissions", nullptr, 'p');
|
||||
args_parser.add_option(recursion_allowed, "Copy directories recursively", "recursive", 'R');
|
||||
args_parser.add_option(recursion_allowed, "Same as -R", nullptr, 'r');
|
||||
args_parser.add_option(verbose, "Verbose", "verbose", 'v');
|
||||
|
@ -32,6 +34,15 @@ int main(int argc, char** argv)
|
|||
args_parser.add_positional_argument(destination, "Destination file path", "destination");
|
||||
args_parser.parse(argc, argv);
|
||||
|
||||
if (preserve) {
|
||||
umask(0);
|
||||
} else {
|
||||
if (pledge("stdio rpath wpath cpath fattr", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool destination_is_existing_dir = Core::File::is_directory(destination);
|
||||
|
||||
for (auto& source : sources) {
|
||||
|
@ -43,7 +54,8 @@ int main(int argc, char** argv)
|
|||
destination_path, source,
|
||||
recursion_allowed ? Core::File::RecursionMode::Allowed : Core::File::RecursionMode::Disallowed,
|
||||
link ? Core::File::LinkMode::Allowed : Core::File::LinkMode::Disallowed,
|
||||
Core::File::AddDuplicateFileMarker::No);
|
||||
Core::File::AddDuplicateFileMarker::No,
|
||||
preserve ? Core::File::PreserveMode::PermissionsOwnershipTimestamps : Core::File::PreserveMode::Nothing);
|
||||
|
||||
if (result.is_error()) {
|
||||
if (result.error().tried_recursing)
|
||||
|
|
Loading…
Add table
Reference in a new issue