2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-06-30 16:19:03 +02:00
|
|
|
* Copyright (c) 2021, Kenneth Myhra <kennethmyhra@serenityos.org>
|
2021-12-25 11:02:56 +01:00
|
|
|
* Copyright (c) 2021, Xavier Defrang <xavier.defrang@gmail.com>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2021-11-27 15:55:40 +01:00
|
|
|
#include <AK/Vector.h>
|
2022-07-23 21:31:49 +02:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2021-12-25 11:02:56 +01:00
|
|
|
#include <LibCore/FilePermissionsMask.h>
|
2021-11-27 15:55:40 +01:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
|
#include <LibMain/Main.h>
|
2019-01-29 04:55:08 +01:00
|
|
|
|
2021-11-27 15:55:40 +01:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2019-01-29 04:55:08 +01:00
|
|
|
{
|
2021-12-25 11:02:56 +01:00
|
|
|
TRY(Core::System::pledge("stdio rpath fattr"));
|
2020-01-12 13:25:02 +01:00
|
|
|
|
2022-07-23 21:31:49 +02:00
|
|
|
StringView mode;
|
|
|
|
|
Vector<StringView> paths;
|
|
|
|
|
|
|
|
|
|
Core::ArgsParser args_parser;
|
|
|
|
|
args_parser.add_positional_argument(mode, "File mode in octal or symbolic notation", "mode");
|
|
|
|
|
args_parser.add_positional_argument(paths, "Paths to file", "paths");
|
|
|
|
|
args_parser.parse(arguments);
|
2019-01-29 04:55:08 +01:00
|
|
|
|
2022-07-23 21:31:49 +02:00
|
|
|
auto mask = TRY(Core::FilePermissionsMask::parse(mode));
|
2019-07-13 22:36:02 +05:00
|
|
|
|
2022-07-23 21:31:49 +02:00
|
|
|
for (auto const& path : paths) {
|
|
|
|
|
auto current_access = TRY(Core::System::stat(path));
|
|
|
|
|
TRY(Core::System::chmod(path, mask.apply(current_access.st_mode)));
|
2019-01-29 04:55:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|