LoginSignup
8
7

More than 5 years have passed since last update.

NSURL のブックマークの “stale” とは何か

Last updated at Posted at 2014-04-03

+[NSURL URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:] メソッドは、ブックマークデータが “stale” (腐りかけ)かどうかを表す真偽値を引数経由で返す。リファレンスによれば、 stale なブックマークデータは破棄し、返り値の URL を使って新たにブックマークデータを生成すべきだという。

ブックマークデータが stale になるのは主に次の2つの場合である:

  • ブックマークが指すファイルが移動されたとき
  • ブックマークが指すファイルが削除され、同じフォルダに同名のファイルが作成されたとき

ブックマークデータはファイルパスとファイルのノード番号を記録しているため、参照先ファイルのパスまたはノード番号の一方が変更された場合でも、他方から URL を解決できるようになっている。解決はできるが情報が古くなっていることを表すのが stale である。

Apple のメーリングリストに詳しい回答があったので以下に訳載しておく:

意訳

“Stale” とは、ブックマークに記録された明白な情報(たとえば親ディレクトリ名とファイル名)を使って参照先のファイルを発見することができなかったが、推測によって得た情報でそれらしいファイルを発見できたことを意味します。その情報はブックマークには記録されていないか、記録されているものと食い違っています。

たとえば、もし参照先のファイルがリネームされていて、ブックマークがファイルシステムのノード番号も記録している場合、ファイルはファイル番号で発見できます。しかし、実際のファイル名とブックマークに記録されたファイル名は食い違っていることになります。これが stale です。

さらに、そのファイルが誤って削除され、バックアップから復元されたとしましょう。ファイルはリネーム後のほうのファイル名を持ち、おそらくはファイル番号も変わっています。こうなると、元のブックマークを解決することはできません。

ブックマークが stale になったら、ファイルのメタデータが変わったということであり、さらなるメタデータの変更でブックマークが壊れるおそれがあります。 Stale だと分かれば、最新のメタデータを持ったより変更耐性のあるブックマークを再生成することができます。

ブックマークを再生成しないという選択肢もあります。再生成すればファイルのメタデータの変更に強いブックマークを作れますが、一方でファイルの移動やリネームを追跡したくない場合もあるでしょうから。

原文

"Stale" means that the referenced file could not be found using the explicit information in the bookmark (such as the parent directory and file name), but a plausible alternative could be found by assuming information that's either not in the bookmark or that contradicts what's in the bookmark.

For example, if the file was renamed, and the bookmark has recorded the file system node number, the original file could be be found via the file number. However, it now has a conflicting name, even though bookmark resolution has "decided" it's the same file.

Now imagine, for example, that the file is accidentally deleted and then restored from a backup, under the newest name. It will likely have a different file number and the original bookmark will now be unresolvable.

When you're told that a bookmark is stale, you're being warned that file metadata has changed, and that further metadata changes may break the bookmark. That gives you the opportunity to re-create the bookmark using the latest metadata, rendering the bookmark more tolerant to future metadata changes.

You can choose to re-create the bookmark or not. The upside to doing so is that your bookmark may more robustly follow a series of file metadata changes. OTOH you may not want to have your bookmark cling to files that are moved or renamed.

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7