File metadata overwritten even when -k (Do not overwrite existing files) is set

17 views
Skip to first unread message

brai...@heroku.com

unread,
Dec 2, 2017, 2:00:59 AM12/2/17
to libarchive-discuss
I'm trying to extract an archive, but leave any existing files untouched. I have tried using the -k (Do not overwrite existing files) option, and this does leave the file contents untouched, but it changes the file metadata, namely the mode and modified time. Below is a sample script demonstrating the problem. Is this a bug and/or is there an option to make -k work like --skip-old-files in GNU tar?

Demo Script

#!/usr/bin/env bash

bsdtar --version

echo "Create an archive with normal files"
rm -rf test-tar
mkdir test-tar
echo "TEST CONTENTS 1" > test-tar/1.txt
echo "TEST CONTENTS 2" > test-tar/2.txt
ls -la test-tar
bsdtar -czf test.tgz test-tar

echo "Change contents and permissions of one of the files"
echo "MORE CONTENTS" >> test-tar/2.txt
chmod 000 test-tar/2.txt
ls -la test-tar

echo "Untar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed"
bsdtar -xzkf test.tgz
ls -la test-tar
cat test-tar/2.txt

echo "Untar the archive without"
bsdtar -xzf test.tgz
ls -la test-tar
cat test-tar/2.txt


Script Output

bsdtar 3.3.2 - libarchive 3.3.2 zlib/1.2.8 liblzma/5.2.3 bz2lib/1.0.6
Create an archive with normal files
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 28 11:19 .
drwxr-xr-x  11 rbrainard  wheel  374 Nov 28 11:19 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 28 11:19 1.txt
-rw-r--r--   1 rbrainard  wheel   16 Nov 28 11:19 2.txt
Change contents and permissions of one of the files
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 28 11:19 .
drwxr-xr-x  11 rbrainard  wheel  374 Nov 28 11:19 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 28 11:19 1.txt
----------   1 rbrainard  wheel   30 Nov 28 11:19 2.txt
Untar the archive with -k (Do not overwrite existing files). The file contents are intact, but the file permissions have changed
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 28 11:19 .
drwxr-xr-x  11 rbrainard  wheel  374 Nov 28 11:19 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 28 11:19 1.txt
-rw-r--r--   1 rbrainard  wheel   30 Nov 28 11:19 2.txt
TEST CONTENTS 2
MORE CONTENTS
Untar the archive without
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 28 11:19 .
drwxr-xr-x  11 rbrainard  wheel  374 Nov 28 11:19 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 28 11:19 1.txt
-rw-r--r--   1 rbrainard  wheel   16 Nov 28 11:19 2.txt
TEST CONTENTS 2

Tim Kientzle

unread,
Dec 2, 2017, 2:01:45 AM12/2/17
to brai...@heroku.com, libarchiv...@googlegroups.com
Would you please file this as an issue on github?

This does sound like a bug, and I'd like to track it there.

Thanks,

Tim
> --
> You received this message because you are subscribed to the Google Groups "libarchive-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to libarchive-disc...@googlegroups.com.
> To post to this group, send email to libarchiv...@googlegroups.com.
> Visit this group at https://groups.google.com/group/libarchive-discuss.
> For more options, visit https://groups.google.com/d/optout.

brai...@heroku.com

unread,
Dec 4, 2017, 1:34:35 AM12/4/17
to libarchive-discuss
Reply all
Reply to author
Forward
0 new messages