소스 검색

Utilities: Add support for setting permissions to `install`

Tim Schumacher 3 년 전
부모
커밋
13ef8469da
1개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      Userland/Utilities/install.cpp

+ 8 - 0
Userland/Utilities/install.cpp

@@ -8,6 +8,7 @@
 #include <AK/Vector.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/File.h>
+#include <LibCore/FilePermissionsMask.h>
 #include <LibCore/System.h>
 #include <LibMain/Main.h>
 
@@ -16,16 +17,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     TRY(Core::System::pledge("stdio rpath wpath cpath fattr"));
 
     bool create_leading_dest_components = false;
+    StringView mode = "0755"sv;
     Vector<StringView> sources;
     StringView destination;
 
     Core::ArgsParser args_parser;
     args_parser.add_ignored(nullptr, 'c'); // "copy files" is the default, no contradicting options exist.
     args_parser.add_option(create_leading_dest_components, "Create leading components of the destination path", nullptr, 'D');
+    args_parser.add_option(mode, "Permissions to set (instead of 0755)", "mode", 'm', "mode");
     args_parser.add_positional_argument(sources, "Source path", "source");
     args_parser.add_positional_argument(destination, "Destination path", "destination");
     args_parser.parse(arguments);
 
+    auto permission_mask = TRY(Core::FilePermissionsMask::parse(mode));
+
     String destination_dir = (sources.size() > 1 ? String { destination } : LexicalPath::dirname(destination));
 
     if (create_leading_dest_components) {
@@ -44,6 +49,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         TRY(Core::File::copy_file_or_directory(final_destination, source, Core::File::RecursionMode::Allowed,
             Core::File::LinkMode::Disallowed, Core::File::AddDuplicateFileMarker::No,
             Core::File::PreserveMode::Nothing));
+
+        auto current_access = TRY(Core::System::stat(final_destination));
+        TRY(Core::System::chmod(final_destination, permission_mask.apply(current_access.st_mode)));
     }
 
     return 0;