diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2020-06-23 01:23:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 01:23:16 -0400 |
commit | 97d4d821894dc58c1419eee998ce5214908af882 (patch) | |
tree | 665e36e7b31e8fa9c7c74827687fbed83081368a /lib/archive.c | |
parent | fa17600efcd09bf74954e728047fded3ff0bd0cd (diff) | |
parent | 9188d893fb00d11a0974582ab1575670777d96cf (diff) | |
download | spmc-97d4d821894dc58c1419eee998ce5214908af882.tar.gz |
Merge pull request #49 from jhunkeler/tar-some-more
Handle unpacking when running as root:
Diffstat (limited to 'lib/archive.c')
-rw-r--r-- | lib/archive.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/archive.c b/lib/archive.c index 6452647..33c1dcd 100644 --- a/lib/archive.c +++ b/lib/archive.c @@ -35,7 +35,7 @@ int tar_extract_file(const char *_archive, const char* _filename, const char *_d strchrdel(destination, SHELL_INVALID); strchrdel(filename, SHELL_INVALID); - sprintf(cmd, "bsdtar -x -f \"%s\" -C \"%s\" \"%s\" 2>&1", archive, destination, filename); + sprintf(cmd, "%s -x -f \"%s\" -C \"%s\" \"%s\" 2>&1", SPM_GLOBAL.tar_program, archive, destination, filename); if (exists(archive) != 0) { fprintf(stderr, "unable to find archive: %s\n", archive); fprintf(SYSERROR); @@ -92,7 +92,13 @@ int tar_extract_archive(const char *_archive, const char *_destination) { // sanitize destination strchrdel(destination, SHELL_INVALID); - sprintf(cmd, "bsdtar -x -f %s -C %s 2>&1", archive, destination); + sprintf(cmd, "%s -x -f %s -C %s ", SPM_GLOBAL.tar_program, archive, destination); + if (SPM_GLOBAL.privileged) { + // Extract the package as if we were a regular user instead of root. + strcat(cmd, "--no-same-owner --no-same-permissions "); + } + strcat(cmd, "2>&1"); + shell(&proc, SHELL_OUTPUT, cmd); if (!proc) { fprintf(SYSERROR); |