mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 17:37:35 +00:00
LibArchive+Utilities: Stop using DeprecatedString
This also slightly improves error propagation in tar, unzip and zip.
This commit is contained in:
parent
8377adfde0
commit
28c99e7a1f
10 changed files with 57 additions and 57 deletions
|
@ -228,7 +228,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
|
||||
auto statbuf = TRY(Core::System::lstat(path));
|
||||
auto canonicalized_path = LexicalPath::canonicalized_path(path);
|
||||
auto canonicalized_path = TRY(String::from_deprecated_string(LexicalPath::canonicalized_path(path)));
|
||||
TRY(tar_stream.add_file(canonicalized_path, statbuf.st_mode, file->read_all()));
|
||||
if (verbose)
|
||||
outln("{}", canonicalized_path);
|
||||
|
@ -239,7 +239,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto add_link = [&](DeprecatedString path) -> ErrorOr<void> {
|
||||
auto statbuf = TRY(Core::System::lstat(path));
|
||||
|
||||
auto canonicalized_path = LexicalPath::canonicalized_path(path);
|
||||
auto canonicalized_path = TRY(String::from_deprecated_string(LexicalPath::canonicalized_path(path)));
|
||||
TRY(tar_stream.add_link(canonicalized_path, statbuf.st_mode, TRY(Core::System::readlink(path))));
|
||||
if (verbose)
|
||||
outln("{}", canonicalized_path);
|
||||
|
@ -250,7 +250,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto add_directory = [&](DeprecatedString path, auto handle_directory) -> ErrorOr<void> {
|
||||
auto statbuf = TRY(Core::System::lstat(path));
|
||||
|
||||
auto canonicalized_path = LexicalPath::canonicalized_path(path);
|
||||
auto canonicalized_path = TRY(String::from_deprecated_string(LexicalPath::canonicalized_path(path)));
|
||||
TRY(tar_stream.add_directory(canonicalized_path, statbuf.st_mode));
|
||||
if (verbose)
|
||||
outln("{}", canonicalized_path);
|
||||
|
|
|
@ -20,16 +20,16 @@
|
|||
static bool unpack_zip_member(Archive::ZipMember zip_member, bool quiet)
|
||||
{
|
||||
if (zip_member.is_directory) {
|
||||
if (mkdir(zip_member.name.characters(), 0755) < 0) {
|
||||
perror("mkdir");
|
||||
if (auto maybe_error = Core::System::mkdir(zip_member.name, 0755); maybe_error.is_error()) {
|
||||
warnln("Failed to create directory '{}': {}", zip_member.name, maybe_error.error());
|
||||
return false;
|
||||
}
|
||||
if (!quiet)
|
||||
outln(" extracting: {}", zip_member.name);
|
||||
return true;
|
||||
}
|
||||
MUST(Core::Directory::create(LexicalPath(zip_member.name).parent(), Core::Directory::CreateDirectories::Yes));
|
||||
auto new_file = Core::File::construct(zip_member.name);
|
||||
MUST(Core::Directory::create(LexicalPath(zip_member.name.to_deprecated_string()).parent(), Core::Directory::CreateDirectories::Yes));
|
||||
auto new_file = Core::File::construct(zip_member.name.to_deprecated_string());
|
||||
if (!new_file->open(Core::OpenMode::WriteOnly)) {
|
||||
warnln("Can't write file {}: {}", zip_member.name, new_file->error_string());
|
||||
return false;
|
||||
|
@ -123,14 +123,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::chdir(output_directory_path));
|
||||
}
|
||||
|
||||
auto success = zip_file->for_each_member([&](auto zip_member) {
|
||||
auto success = TRY(zip_file->for_each_member([&](auto zip_member) {
|
||||
bool keep_file = false;
|
||||
|
||||
if (!file_filters.is_empty()) {
|
||||
for (auto& filter : file_filters) {
|
||||
// Convert underscore wildcards (usual unzip convention) to question marks (as used by StringUtils)
|
||||
auto string_filter = filter.replace("_"sv, "?"sv, ReplaceMode::All);
|
||||
if (zip_member.name.matches(string_filter, CaseSensitivity::CaseSensitive)) {
|
||||
if (zip_member.name.bytes_as_string_view().matches(string_filter, CaseSensitivity::CaseSensitive)) {
|
||||
keep_file = true;
|
||||
break;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}));
|
||||
|
||||
return success ? 0 : 1;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
||||
auto file_buffer = TRY(file->read_until_eof());
|
||||
Archive::ZipMember member {};
|
||||
member.name = canonicalized_path;
|
||||
member.name = TRY(String::from_deprecated_string(canonicalized_path));
|
||||
|
||||
auto deflate_buffer = Compress::DeflateCompressor::compress_all(file_buffer);
|
||||
if (deflate_buffer.has_value() && deflate_buffer.value().size() < file_buffer.size()) {
|
||||
|
@ -79,7 +79,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto add_directory = [&](DeprecatedString path, auto handle_directory) -> ErrorOr<void> {
|
||||
auto canonicalized_path = DeprecatedString::formatted("{}/", LexicalPath::canonicalized_path(path));
|
||||
Archive::ZipMember member {};
|
||||
member.name = canonicalized_path;
|
||||
member.name = TRY(String::from_deprecated_string(canonicalized_path));
|
||||
member.compressed_data = {};
|
||||
member.compression_method = Archive::ZipCompressionMethod::Store;
|
||||
member.uncompressed_size = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue