mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
5e1499d104
This commit un-deprecates DeprecatedString, and repurposes it as a byte string. As the null state has already been removed, there are no other particularly hairy blockers in repurposing this type as a byte string (what it _really_ is). This commit is auto-generated: $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \ Meta Ports Ladybird Tests Kernel) $ perl -pie 's/\bDeprecatedString\b/ByteString/g; s/deprecated_string/byte_string/g' $xs $ clang-format --style=file -i \ $(git diff --name-only | grep \.cpp\|\.h) $ gn format $(git ls-files '*.gn' '*.gni')
60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2023, Tim Ledbetter <timledbetter@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/LexicalPath.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibCore/ArgsParser.h>
|
|
#include <LibCore/System.h>
|
|
#include <LibMain/Main.h>
|
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
{
|
|
TRY(Core::System::pledge("stdio cpath"));
|
|
|
|
bool remove_parents = false;
|
|
bool verbose = false;
|
|
Vector<StringView> paths;
|
|
|
|
Core::ArgsParser args_parser;
|
|
args_parser.add_option(remove_parents, "Remove all directories in each given path", "parents", 'p');
|
|
args_parser.add_option(verbose, "List each directory as it is removed", "verbose", 'v');
|
|
args_parser.add_positional_argument(paths, "Directories to remove", "paths");
|
|
args_parser.parse(arguments);
|
|
|
|
int status = 0;
|
|
|
|
auto remove_directory = [&](StringView path) {
|
|
if (verbose)
|
|
outln("rmdir: removing directory '{}'", path);
|
|
|
|
auto maybe_error = Core::System::rmdir(path);
|
|
if (maybe_error.is_error()) {
|
|
warnln("Failed to remove '{}': {}", path, maybe_error.release_error());
|
|
status = 1;
|
|
}
|
|
|
|
return !maybe_error.is_error();
|
|
};
|
|
|
|
for (auto path : paths) {
|
|
if (!remove_directory(path) || !remove_parents)
|
|
continue;
|
|
|
|
LexicalPath lexical_path(path);
|
|
auto const& path_parts = lexical_path.parts_view();
|
|
if (path_parts.size() < 2)
|
|
continue;
|
|
|
|
for (size_t i = path_parts.size() - 1; i > 0; --i) {
|
|
auto current_path_parts = path_parts.span().slice(0, i);
|
|
LexicalPath current_path { ByteString::join('/', current_path_parts) };
|
|
if (!remove_directory(current_path.string()))
|
|
break;
|
|
}
|
|
}
|
|
return status;
|
|
}
|