2009年3月3日火曜日

MacPortsのselfupdateを忘れた→はまる

MacPortsは各portのバージョンや依存関係といった情報をローカルなファイルに保存している。そのportがインストールされていなくても、である。これがちょっとした問題になることがある。

結論を先に書くと、selfupdateは定期的に実行しなければいけない。

例1:ローカルの情報が古いと旧バージョンのportがインストールされる

caml-sqlite3というportを例に説明してみる。現時点でcaml-sqlite3の最新版は1.3.0だ。

ところが、私の環境でcaml-sqlite3を入れようとすると1.2.0を取りに行く。

# port -v fetch caml-sqlite3
---> Fetching caml-sqlite3
---> ocaml-sqlite3-1.2.0.tar.gz doesn't seem to exist in /opt/local/var/macports/distfiles/caml-sqlite3
---> Attempting to fetch ocaml-sqlite3-1.2.0.tar.gz from http://www.ocaml.info/ocaml_sources/

こうなるのは、私のLeopard上にあるPortfileが古いからだ。このファイルはMacPortsをインストールしたときに作成されている。

# grep version /opt/local/var/macports/sources/rsync.macports.org/release/ports/devel/caml-sqlite3/Portfile 
version 1.2.0
distname ocaml-sqlite3-${version}
#

例2:portがインストールできないこともある

上の場合は旧バージョンの1.2.0がまだ1.3.0同様ダウンロードできるのでまだ良いが、portによっては旧バージョンがダウンロードできない場合もある。p5-errorがその例だ。

# port install p5-error
---> Fetching p5-error
---> Attempting to fetch Error-0.17012.tar.gz from http://ftp.ucr.ac.cr/Unix/CPAN/modules/by-module/Error
(略)
Error: Target org.macports.fetch returned: fetch failed
Error: Status 1 encountered during processing.
#

port installの裏側ではError-0.17012.tar.gzを取りに行っているのにサーバ側には最新版(0.17015)しかないためにダウンロードが失敗している。

解決方法

上の問題を解決するにはselfupdateというコマンドを実行する。

# port selfupdate

出力はこれのどちらかになるようだが

  • selfupdate done!
  • The MacPorts installation is not outdated so it was not updated

どちらにしても/opt/local/var/macports/sources/rsync.macports.org/release/ports/以下のファイルが更新される。

selfupdateを行った後に先のcaml-sqliteでもう一度試してみると無事1.3.0をダウンロードしてくれる。

# port -v fetch caml-sqlite3
---> Fetching caml-sqlite3
---> ocaml-sqlite3-1.3.0.tar.gz doesn't seem to exist in /opt/local/var/macports/distfiles/caml-sqlite3
---> Attempting to fetch ocaml-sqlite3-1.3.0.tar.gz from http://www.ocaml.info/ocaml_sources/

selfupdateは定期的に実行する

今までselfupdateはその名前からして/opt/local/bin/portのバイナリを更新するだけのものだと思っていたが、実はそうではなかった。MacPortsのWikiにこうある。

Selfupdate is the command used to automatically download new Portfiles so that your local copy of MacPorts is aware of new MacPorts software or upgrades to existing software that have been committed to the MacPorts infrastructure. Additionally, this command is used to update the MacPorts software itself - think of it is a Software Update, like its name suggests.

(抄訳)selfupdateコマンドを使うと更新のあったPortfile群をダウンロードできる。さらに、selfupdateの名前のとおり、インストールされているMacPortsのバイナリ自身を更新する。

Selfupdate is a command that can safely be scheduled to automatically run, as it doesn't actually update your installed software, it just "teaches" MacPorts about new updates. Take a look at using crontabs to run your selfupdate.

(抄訳)selfupdateコマンドは更新情報をダウンロードするだけのものなので実際にソフトウェアの更新を行うわけではない。そのため自動的に実行しても安全だ。

実行しても安全というか、実行しないと更新情報が同期できないのだ。

私のcronの設定

rootのcrontabをこのように設定した。

# 毎日午前1:23にselfupdateを実行
23 1 * * * /opt/local/bin/port selfupdate

どこか気持ち悪い

上記をまとめると、

  • MacPortsを安心して使うにはport selfupdateの実行が不可欠
  • selfupdateはcronで定期的に走らせるのが一番

となるのだがどうにも気持ち悪い。

ウェブの世界に例えると、ローカルに保存されたPortfileはHTTPのキャッシュに近いが、自分でキャッシュの更新(selfupdate)をしない限りブラウザが永遠に古いキャッシュを参照しているという状態になっている。Yahooで昨日の検索結果が表示されるのは構わないが、昨日の天気予報が出てくるのはいやだ。

サーバの更新情報をローカルに保存する仕組みの是非はともかく、ユーザが何もしないとその情報が更新されないのが腑に落ちない。MacPortsは他のところがうまくできているので、不思議でならない。サーバ側で走らせるデーモンをrsyncだけにしたかったのだろうか。

0 件のコメント:

コメントを投稿