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?
#!/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
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