summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorcircl <circl.lastname@gmail.com>2022-01-02 21:42:25 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-01-04 06:22:34 +0000
commit69c757e92fd164c053ff4ed0e7ad75d8ecf71773 (patch)
treef8a3a5f6c1ae1561e9630a73c5bf70578ca7fae3 /Userland
parent6124050187b5bd11532829ce1ef7559cccca4143 (diff)
downloadserenity-69c757e92fd164c053ff4ed0e7ad75d8ecf71773.zip
tar: Implement -C option
This allows specifying which directory to extract to or create from. I would have used the *at variants of the functions, but some weren't implemented yet.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/tar.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/Userland/Utilities/tar.cpp b/Userland/Utilities/tar.cpp
index fc98681a84..da2db3699a 100644
--- a/Userland/Utilities/tar.cpp
+++ b/Userland/Utilities/tar.cpp
@@ -29,6 +29,7 @@ int main(int argc, char** argv)
bool verbose = false;
bool gzip = false;
const char* archive_file = nullptr;
+ const char* directory = nullptr;
Vector<const char*> paths;
Core::ArgsParser args_parser;
@@ -36,7 +37,8 @@ int main(int argc, char** argv)
args_parser.add_option(extract, "Extract archive", "extract", 'x');
args_parser.add_option(list, "List contents", "list", 't');
args_parser.add_option(verbose, "Print paths", "verbose", 'v');
- args_parser.add_option(gzip, "compress or uncompress file using gzip", "gzip", 'z');
+ args_parser.add_option(gzip, "Compress or decompress file using gzip", "gzip", 'z');
+ args_parser.add_option(directory, "Directory to extract to/create from", "directory", 'C', "DIRECTORY");
args_parser.add_option(archive_file, "Archive file", "file", 'f', "FILE");
args_parser.add_positional_argument(paths, "Paths", "PATHS", Core::ArgsParser::Required::No);
args_parser.parse(argc, argv);
@@ -58,6 +60,13 @@ int main(int argc, char** argv)
file = maybe_file.value();
}
+ if (directory) {
+ if (chdir(directory) < 0) {
+ perror("chdir");
+ return 1;
+ }
+ }
+
Core::InputFileStream file_stream(file);
Compress::GzipDecompressor gzip_stream(file_stream);
@@ -160,6 +169,13 @@ int main(int argc, char** argv)
file = maybe_file.value();
}
+ if (directory) {
+ if (chdir(directory) < 0) {
+ perror("chdir");
+ return 1;
+ }
+ }
+
Core::OutputFileStream file_stream(file);
Compress::GzipCompressor gzip_stream(file_stream);