pacmanでfailed to commit transactionが出た場合の対処法

ごちゃまぜ技術系

先日パッケージアップデートをしようとしたら,なぜか上手くアップデートが走らず困りました.今後も同じことが起こりそうなので解決方法を備忘録として残しておこうと思います.

発生した問題

いつものように以下で,パッケージアップデートを行います.

sudo pacman -Syu

実行すると,こんな感じのエラーがました.

:: Proceed with installation? [Y/n] Y
checking keyring...
checking package integrity...
loading package files...
checking for file conflicts...
error: failed to commit transaction (conflicting files)
node-gyp: /usr/lib/node_modules/node-gyp/node_modules/lru-cache/LICENSE.md exists in filesystem
npm: /usr/lib/node_modules/npm/docs/content/commands/npm-get.md exists in filesystem
npm: /usr/lib/node_modules/npm/docs/content/commands/npm-ll.md exists in filesystem
npm: /usr/lib/node_modules/npm/docs/content/commands/npm-set.md exists in filesystem
npm: /usr/lib/node_modules/npm/docs/content/commands/npm-trust.md exists in filesystem
npm: /usr/lib/node_modules/npm/docs/output/commands/npm-get.html exists in filesystem
npm: /usr/lib/node_modules/npm/docs/output/commands/npm-ll.html exists in filesystem
npm: /usr/lib/node_modules/npm/docs/output/commands/npm-set.html exists in filesystem
npm: /usr/lib/node_modules/npm/docs/output/commands/npm-trust.html exists in filesystem
npm: /usr/lib/node_modules/npm/lib/commands/trust/github.js exists in filesystem
npm: /usr/lib/node_modules/npm/lib/commands/trust/gitlab.js exists in filesystem
npm: /usr/lib/node_modules/npm/lib/commands/trust/index.js exists in filesystem
npm: /usr/lib/node_modules/npm/lib/commands/trust/list.js exists in filesystem
npm: /usr/lib/node_modules/npm/lib/commands/trust/revoke.js exists in filesystem
npm: /usr/lib/node_modules/npm/lib/trust-cmd.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/@sigstore/sign/dist/config.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/@sigstore/sign/dist/external/rekor-v2.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/@sigstore/verify/dist/tlog/checkpoint.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/@sigstore/verify/dist/tlog/merkle.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/@sigstore/verify/dist/tlog/set.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/common-ancestor-path/LICENSE.md exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/common-ancestor-path/dist/commonjs/index.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/common-ancestor-path/dist/commonjs/package.json exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/common-ancestor-path/dist/esm/index.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/common-ancestor-path/dist/esm/package.json exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/glob/dist/commonjs/index.min.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/glob/dist/esm/index.min.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/LICENSE.md exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/commonjs/index.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/commonjs/index.min.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/commonjs/options.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/commonjs/package.json exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/commonjs/posix.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/commonjs/win32.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/esm/index.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/esm/index.min.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/esm/options.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/esm/package.json exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/esm/posix.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/isexe/dist/esm/win32.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/lru-cache/LICENSE.md exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/minipass-sized/dist/commonjs/index.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/minipass-sized/dist/commonjs/package.json exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/minipass-sized/dist/esm/index.js exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/minipass-sized/dist/esm/package.json exists in filesystem
npm: /usr/lib/node_modules/npm/node_modules/validate-npm-package-name/lib/builtin-modules.json exists in filesystem
Errors occurred, no packages were upgraded.

なんじゃこりゃ!!

原因

困ったらwikiを見ればなんとかなります.すると,以下の説明を発見.

pacman - ArchWiki

“This is happening because pacman has detected a file conflict, and by design, will not overwrite files for you”
なるほど,「ファイルが競合していて,仕様上,上書きできないよ」ということらしい.

解決方法

先程のwikiの手順に従って,解決します.
” A safe way is to first check if another package owns the file (pacman -Qo /path/to/file). “
ということで,まず他のパッケージにエラーを吐いたファイルが所有されているかを以下のコマンドで確かめます.
オプションについて少し解説すると,-Qでパッケージデータベースに問い合わせ,oで指定したファイルを含んでいるパッケージを検索するという感じです.

pacman -Qo /path/to/file

(例)

pacman -Qo /usr/lib/node_modules/node-gyp/node_modules/lru-cache/LICENSE.md /usr/lib/node_modules/npm/docs/content/commands/npm-get.md ...

その結果,誰も所有していなければOKです(所有されていたらバグレポートらしい).
そしたら,
“If the file is not owned by another package, rename the file which “exists in filesystem” and re-issue the update command.rm”
ということで,ファイル名称を変更してあげます.
(なお,私は説明を読み間違えて,全部のファイルを消して対処したので,リネームで行けるかは未確認.次出た時確認します.とりあえず解決できたので,rmの方を載せておきます.)

sudo rm /path/to/file

(例)
コマンドを作る際は,vscodeで縦選択やら置換などを使って,コマンドを作成しました(多分もっといい方法が在る気がするのでコメントなどで教えていただけると嬉しいです).

sudo rm /usr/lib/node_modules/node-gyp/node_modules/lru-cache/LICENSE.md /usr/lib/node_modules/npm/docs/content/commands/npm-get.md ...

最後に,いつものアップデートコマンドを打ち込みます.

sudo pacman -Syu

おわりに

今回はパッケージアップデートをしようとしたら失敗した話を書いてみました.
いつも動いてたコマンドが動かなくなると,環境壊したかと思って色々と焦りますよね.
同じ様に困っている人の助けになれば幸いです.
間違い等ありましたらコメントで教えていただけると嬉しいです.

コメント

タイトルとURLをコピーしました