👌

dpkgがzstdに対応していなかったときの対応

2023/08/10に公開

検索すればすぐに出てくるんですが日本語の記事がパッと見つからなかったのでここに記事化します。

発生した問題

Debian 11ベースの環境でwatchmanをインストールしようと思ったら dpkg-deb: error: archive '/tmp/watchman_ubuntu22.04_v2023.05.01.00.deb' uses unknown compression for member 'control.tar.zst', giving up というエラーが発生してしまいました。

$ gh release download v2023.05.01.00 -R facebook/watchman --pattern 'watchman_ubuntu22.04_v2023.05.01.00.deb'
$ sudo apt install ./watchman_ubuntu22.04_v2023.05.01.00.deb 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'watchman' instead of './watchman_ubuntu22.04_v2023.05.01.00.deb'
The following NEW packages will be installed:
  watchman
0 upgraded, 1 newly installed, 0 to remove and 9 not upgraded.
Need to get 0 B/3,361 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 /tmp/watchman_ubuntu22.04_v2023.05.01.00.deb watchman amd64 20230430.125247.0 [3,361 kB]
dpkg-deb: error: archive '/tmp/watchman_ubuntu22.04_v2023.05.01.00.deb' uses unknown compression for member 'control.tar.zst', giving up
dpkg: error processing archive /tmp/watchman_ubuntu22.04_v2023.05.01.00.deb (--unpack):
 dpkg-deb --control subprocess returned error exit status 2
Errors were encountered while processing:
 /tmp/watchman_ubuntu22.04_v2023.05.01.00.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

最初はzstdをインストールすれば良いだけかと思いましたが調べてみるとDebian 11のdpkgコマンドはエラー通り『dpkgがzstdに対応していない』ようです。なのでzstdをインストールするだけでは解決しませんでした。

解決策

https://unix.stackexchange.com/a/745467 に紹介されている方法で解決しました。やっていることは実にシンプルで

  1. .debを展開
  2. zstdをxzに変換
  3. .debに再アーカイブ
  4. 再アーカイブした.debをインストール

というものです。
※zstdをxzに変換する際にzstdを使うのでどのみちzstdのインストールは必要です。

$ ar x watchman_ubuntu22.04_v2023.05.01.00.deb
$ zstd -d < control.tar.zst | xz > control.tar.xz
$ zstd -d < data.tar.zst | xz > data.tar.xz
$ ar -m -c -a sdsd  watchman.deb debian-binary control.tar.xz data.tar.xz
$ sudo apt install ./watchman.deb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'watchman' instead of './watchman.deb'
The following NEW packages will be installed:
  watchman
0 upgraded, 1 newly installed, 0 to remove and 9 not upgraded.
Need to get 0 B/3,034 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 /tmp/watchman.deb watchman amd64 20230430.125247.0 [3,034 kB]
Selecting previously unselected package watchman.
(Reading database ... 43861 files and directories currently installed.)
Preparing to unpack /tmp/watchman.deb ...
Unpacking watchman (20230430.125247.0) ...
Setting up watchman (20230430.125247.0) ...

ちゃんとインストールできましたね。

Discussion