bsdtar:既存のファイル情報の上書きを防ぐ方法は?

bsdtar:既存のファイル情報の上書きを防ぐ方法は?

bsdtar-k (Do not overwrite existing files)既存のファイルの内容は変更しませんが、まだファイル情報(権限など)をアーカイブコンテンツで上書きするオプションがあります。 GNU tarのオプションbsdtarのように、ファイル情報をそのまま維持しながら既存のファイルの上書きを完全にスキップする方法はありますか?--skip-old-files

以下は問題を示すスクリプトです。

#!/usr/bin/env bash

echo -e "\nCreate 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 -e "\nChange 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 -e "\nUntar 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 -e "\nUntar the archive without -k"
bsdtar -xzf test.tgz
ls -la test-tar
cat test-tar/2.txt

スクリプトの出力は次のとおりです。

Create an archive with normal files
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 29 17:53 .
drwxr-xr-x  14 rbrainard  wheel  476 Nov 29 17:53 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 1.txt
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 2.txt

Change contents and permissions of one of the files
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 29 17:53 .
drwxr-xr-x  14 rbrainard  wheel  476 Nov 29 17:53 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 1.txt
----------   1 rbrainard  wheel   30 Nov 29 17:53 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 29 17:53 .
drwxr-xr-x  14 rbrainard  wheel  476 Nov 29 17:53 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 1.txt
-rw-r--r--   1 rbrainard  wheel   30 Nov 29 17:53 2.txt
TEST CONTENTS 2
MORE CONTENTS

Untar the archive without -k
total 16
drwxr-xr-x   4 rbrainard  wheel  136 Nov 29 17:53 .
drwxr-xr-x  14 rbrainard  wheel  476 Nov 29 17:53 ..
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 1.txt
-rw-r--r--   1 rbrainard  wheel   16 Nov 29 17:53 2.txt
TEST CONTENTS 2

私のbsdtarバージョンはです3.3.2

ベストアンサー1

これがバグであることがわかりました。私はこれを次のアドレスにクロスポストしました。 libarchive ディスカッションある管理者が応答しました。問題が提出された場所:https://github.com/libarchive/libarchive/issues/972

おすすめ記事