mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:07:44 +00:00
Utilites: Implement unzip -q
This commit is contained in:
parent
c247d7a662
commit
3fa5b27931
1 changed files with 10 additions and 5 deletions
|
@ -14,14 +14,15 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static bool unpack_zip_member(Archive::ZipMember zip_member)
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
outln(" extracting: {}", zip_member.name);
|
||||
if (!quiet)
|
||||
outln(" extracting: {}", zip_member.name);
|
||||
return true;
|
||||
}
|
||||
auto new_file = Core::File::construct(zip_member.name);
|
||||
|
@ -30,7 +31,8 @@ static bool unpack_zip_member(Archive::ZipMember zip_member)
|
|||
return false;
|
||||
}
|
||||
|
||||
outln(" extracting: {}", zip_member.name);
|
||||
if (!quiet)
|
||||
outln(" extracting: {}", zip_member.name);
|
||||
|
||||
// TODO: verify CRC32s match!
|
||||
switch (zip_member.compression_method) {
|
||||
|
@ -73,11 +75,13 @@ int main(int argc, char** argv)
|
|||
{
|
||||
const char* path;
|
||||
int map_size_limit = 32 * MiB;
|
||||
bool quiet { false };
|
||||
String output_directory_path;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(map_size_limit, "Maximum chunk size to map", "map-size-limit", 0, "size");
|
||||
args_parser.add_option(output_directory_path, "Directory to receive the archive content", "output-directory", 'd', "path");
|
||||
args_parser.add_option(quiet, "Be less verbose", "quiet", 'q');
|
||||
args_parser.add_positional_argument(path, "File to unzip", "path", Core::ArgsParser::Required::Yes);
|
||||
args_parser.parse(argc, argv);
|
||||
|
||||
|
@ -107,7 +111,8 @@ int main(int argc, char** argv)
|
|||
}
|
||||
auto& mapped_file = *file_or_error.value();
|
||||
|
||||
warnln("Archive: {}", zip_file_path);
|
||||
if (!quiet)
|
||||
warnln("Archive: {}", zip_file_path);
|
||||
|
||||
auto zip_file = Archive::Zip::try_create(mapped_file.bytes());
|
||||
if (!zip_file.has_value()) {
|
||||
|
@ -130,7 +135,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
auto success = zip_file->for_each_member([&](auto zip_member) {
|
||||
return unpack_zip_member(zip_member) ? IterationDecision::Continue : IterationDecision::Break;
|
||||
return unpack_zip_member(zip_member, quiet) ? IterationDecision::Continue : IterationDecision::Break;
|
||||
});
|
||||
|
||||
return success ? 0 : 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue