whileループでtarを使用してファイルにアーカイブを更新しますか?

whileループでtarを使用してファイルにアーカイブを更新しますか?

ここに質問をリストしました。2019 年 10 月アップグレード: pip アップグレードに失敗しました · 問題 #5844 · msys2/MINGW-packages:デフォルトでは、pipMSYS2では一部のファイルが表示されるため、更新を拒否しています。pacman -Syu基本的にこれをダンプします。

...
:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 mingw-w64-x86_64-gl...     4.6 MiB  4.97M/s 00:01 [#####################] 100%
 mingw-w64-x86_64-gn...  1942.9 KiB  1045K/s 00:02 [#####################] 100%
(18/18) checking keys in keyring                   [#####################] 100%
(18/18) checking package integrity                 [#####################] 100%
(18/18) loading package files                      [#####################] 100%
(18/18) checking for file conflicts                [#####################] 100%
error: failed to commit transaction (conflicting files)
python2-pip: /c/msys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.py exists in filesystem
python2-pip: /c/msys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.pyc exists in filesystem
...

pipを削除したくないのですが(パックマン「ファイルシステムに存在します」エラー)ファイルを別の場所に「ただ」移動して更新を実行できます。もちろん、移動するファイルの元のファイルの場所を保存したいと思います。

tarだから私はこれらのファイルをアーカイブに保存し(--remove-files元のファイルも削除して再度更新しないように)、更新後に復元できると思いました。すでにインストールされている他のパッケージが必要な場合です。

tar残念ながら、ループ内のファイルでアーカイブを更新する正しい呼び出しが実際に見つかりませんwhile(つまり、スペースで区切られた「1行」のファイルのリストはありません)。

これにより、アーカイブにファイルが1つだけ作成されます。

$ pacman -Syu | grep exists | awk '{print $2}' | while read f; do tar -czf /tmp/bckp.tar "$f"; done
:: Proceed with installation? [Y/n] y
error: failed to commit transaction (conflicting files)
tar: Removing leading `/' from member names
tar: Removing leading `/' from member names
tar: Removing leading `/' from member names
...

$ tar tzvf /tmp/bckp.tar
-rw-r--r-- user/None       13854 2019-09-02 09:07 c/msys64/usr/lib/python3.7/site-packages/pip/_vendor/urllib3/packages/rfc3986/validators.py

これは実行されません:

$ pacman -Syu | grep exists | awk '{print $2}' | while read f; do tar -czvf --strip-components=1 --append /tmp/bckp.tar.gz "$f"; done
:: Proceed with installation? [Y/n] y
error: failed to commit transaction (conflicting files)
tar: You may not specify more than one '-Acdtrux', '--delete' or  '--test-label' option
Try 'tar --help' or 'tar --usage' for more information.
tar: You may not specify more than one '-Acdtrux', '--delete' or  '--test-label' option
Try 'tar --help' or 'tar --usage' for more information.
...

これも同様です。

$ pacman -Syu | grep exists | awk '{print $2}' | while read f; do tar -zvf --strip-components=1 --append /tmp/bckp.tar.gz "$f"; done
:: Proceed with installation? [Y/n] y
error: failed to commit transaction (conflicting files)
tar: Cannot update compressed archives
Try 'tar --help' or 'tar --usage' for more information.
tar: Cannot update compressed archives
Try 'tar --help' or 'tar --usage' for more information.
...

これにより、既存のファイルに対して「該当するファイルまたはディレクトリがありません」というメッセージが表示されます。

$ pacman -Syu | grep exists | awk '{print $2}' | while read f; do tar -vf --strip-components=1 --append /tmp/bckp.tar.gz "$f"; done
:: Proceed with installation? [Y/n] y
error: failed to commit transaction (conflicting files)
tar: Removing leading `/' from member names
tar: /tmp/bckp.tar.gz: Cannot stat: No such file or directory
/c/msys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.py
tar: Removing leading `/' from hard link targets
tar: Exiting with failure status due to previous errors
tar: Removing leading `/' from member names
tar: /tmp/bckp.tar.gz: Cannot stat: No such file or directory
/c/msys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.pyc
...

/c/msys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.pycしたがって、次の形式のループにファイルリスト(絶対ファイルパス)があるとします。絶対パスの最初の部分が削除された状態でアーカイブに入るようにすべてのwhileファイルをアーカイブに追加するにはどうすればよいですか(たとえば、.tar上記のファイルは終了しますtarmsys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.pyc

ベストアンサー1

さて、最後に正しい呼び出しを見つけたようです。追加は抽出に適用されるsedためです。--strip-componentsただ;ここでは、/c/ファイルパス文字列から手動で削除し、tar変更ディレクトリにスイッチを/c/使用するように指示します。-C

$ pacman -Syu | grep exists | awk '{print $2}' | sed 's_/c/__' | xargs tar -cvf /tmp/bckp.tar -C /c/
:: Proceed with installation? [Y/n] y
error: failed to commit transaction (conflicting files)
msys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.py
msys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.pyc
msys64/usr/lib/python2.7/site-packages/pip/_internal/distributions/__init__.py
msys64/usr/lib/python2.7/site-packages/pip/_internal/distributions/__init__.pyc
...

...そしてもう一度確認してください。

$ tar tvf /tmp/bckp.tar
-rw-r--r-- user/None        3360 2019-09-02 09:08 msys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.py
-rw-r--r-- user/None        4154 2019-09-02 09:08 msys64/usr/lib/python2.7/site-packages/pip/_internal/commands/debug.pyc
-rw-r--r-- user/None         861 2019-09-02 09:08 msys64/usr/lib/python2.7/site-packages/pip/_internal/distributions/__init__.py
-rw-r--r-- user/None         986 2019-09-02 09:08 msys64/usr/lib/python2.7/site-packages/pip/_internal/distributions/__init__.pyc
...

おすすめ記事