diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-12-19 15:08:16 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-12-19 15:08:16 +0100 |
commit | 2550c11373e83f4c6085049dc9efe53f8389b035 (patch) | |
tree | 7d543d778d62393f2cf535eaf37c87f5b92a3661 /src/libutil | |
parent | be32da0ed0233c6a8813b89eeececf9af49ad243 (diff) |
tarfile.cc: Don't change the cwd
Nix is multithreaded so it's not safe to change the cwd.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/tarfile.cc | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/src/libutil/tarfile.cc b/src/libutil/tarfile.cc index c85a8b0cb..ca19f402e 100644 --- a/src/libutil/tarfile.cc +++ b/src/libutil/tarfile.cc @@ -80,34 +80,12 @@ private: } }; -struct PushD { - char * oldDir; - - PushD(const std::string &newDir) { - oldDir = getcwd(0, 0); - if (!oldDir) throw SysError("getcwd"); - int r = chdir(newDir.c_str()); - if (r != 0) throw SysError("changing directory to tar output path"); - } - - ~PushD() { - int r = chdir(oldDir); - free(oldDir); - if (r != 0) - warn("failed to change directory back after tar extraction"); - /* can't throw out of a destructor */ - } -}; - static void extract_archive(TarArchive & archive, const Path & destDir) { - // need to chdir back *after* archive closing - PushD newDir(destDir); int flags = ARCHIVE_EXTRACT_FFLAGS | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_SECURE_SYMLINKS - | ARCHIVE_EXTRACT_SECURE_NODOTDOT - | ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS; + | ARCHIVE_EXTRACT_SECURE_NODOTDOT; for (;;) { struct archive_entry * entry; @@ -118,6 +96,9 @@ static void extract_archive(TarArchive & archive, const Path & destDir) else archive.check(r); + archive_entry_set_pathname(entry, + (destDir + "/" + archive_entry_pathname(entry)).c_str()); + archive.check(archive_read_extract(archive.archive, entry, flags)); } |