ladybird/Userland/Utilities/chmod.cpp

36 lines
1.0 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Kenneth Myhra <kennethmyhra@serenityos.org>
* Copyright (c) 2021, Xavier Defrang <xavier.defrang@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Vector.h>
2022-07-23 22:31:49 +03:00
#include <LibCore/ArgsParser.h>
#include <LibCore/FilePermissionsMask.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath fattr"));
2020-01-12 15:25:02 +03:00
2022-07-23 22:31:49 +03: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);
2022-07-23 22:31:49 +03:00
auto mask = TRY(Core::FilePermissionsMask::parse(mode));
2022-07-23 22:31:49 +03: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)));
}
return 0;
}