Utilities: tar: Always create parent directory when extracting
This commit is contained in:
parent
3425730294
commit
bd6c48f6ea
Notes:
sideshowbarker
2024-07-18 01:19:02 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/bd6c48f6ea5 Pull-request: https://github.com/SerenityOS/serenity/pull/10858
1 changed files with 8 additions and 2 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <LibCompress/Gzip.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/FileStream.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
@ -75,10 +76,13 @@ int main(int argc, char** argv)
|
|||
Archive::TarFileStream file_stream = tar_stream.file_contents();
|
||||
|
||||
const Archive::TarFileHeader& header = tar_stream.header();
|
||||
String absolute_path = Core::File::absolute_path(header.filename());
|
||||
switch (header.type_flag()) {
|
||||
case Archive::TarFileType::NormalFile:
|
||||
case Archive::TarFileType::AlternateNormalFile: {
|
||||
int fd = open(String(header.filename()).characters(), O_CREAT | O_WRONLY, header.mode());
|
||||
Core::File::ensure_parent_directories(absolute_path);
|
||||
|
||||
int fd = open(absolute_path.characters(), O_CREAT | O_WRONLY, header.mode());
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
return 1;
|
||||
|
@ -96,7 +100,9 @@ int main(int argc, char** argv)
|
|||
break;
|
||||
}
|
||||
case Archive::TarFileType::Directory: {
|
||||
if (mkdir(String(header.filename()).characters(), header.mode())) {
|
||||
Core::File::ensure_parent_directories(absolute_path);
|
||||
|
||||
if (mkdir(absolute_path.characters(), header.mode())) {
|
||||
perror("mkdir");
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue