4

An application I was using had a .dockset file stored in my home directory. I moved this file, and the application automatically updated the location of the file. I notice a similar effect when moving files that I'm currently editing in apps like Xcode, TextEdit, BBEdit, Preview, iWork, etc.

How does Mac OS keep track of these file movements?

  • The answer is something like inotify, dnotify, or something related to those technologies. Hey look what I found on SO: stackoverflow.com/a/5171644/106813 – Jason Salaz Apr 3 '14 at 7:23
  • 2
    @JasonSalaz I doubt it very much; these are related to the Linux kernel which has nothing to do with Mac OS. My (incompetent) guess would rather be that, when the app is running, the file isn’t identified by its path, but via a file id of some sort, such as its index node. Perhaps with an event just signaling the file was moved to the app. – Édouard Apr 3 '14 at 10:09
  • First off, that's why I didn't answer it and merely commented, to set the OP off on the right direction. I know of those components from the Linux Kernel, but my knowledge of the mach / darwin kernels is not nearly as extensive. Note that the link to Stack Overflow gives an exact function call and signal defined as "the substitute [to use] on mac os x". – Jason Salaz Apr 4 '14 at 2:34
2

From a higher point of view (in opposite to the low level implementation) this is probably related to NSURL's bookmark capabilities.

A bookmark provides a persistent reference to a file-system resource. When you resolve a bookmark, you obtain a URL to the resource’s current location. A bookmark’s association with a file-system resource (typically a file or folder) usually continues to work if the user moves or renames the resource, or if the user relaunches your app or restarts the system.

2

Most Apps don't use the Bookmarks (mentioned by Matthieu) for this purpose, because Bookmarks are meant to locate a file after the app has been quit in between), but rather either keep the file open while the app runs, or reference the file using its File ID (aka CNID or objID), or simply by using a NSURL object that keeps track of the file.

The secret to this working is that HFS(+) volumes assign each file and folder a unique number (the CNID), and so even if the file is renamed or moved, it can be looked up by that number again. Bookmarks also make use of this number by storing it for this purpose.

This also means that if you place your file on a file system that does not support file IDs, e.g. on a SMB network volume or a FAT formatted disk, renaming and moving of such files may NOT be detected by those apps, because there's no alternative tracking mechanism in this case.

See also Apple's Technical QA1113: The /.vol/ dir and volFS.

APFS, Apple's new volume format, does support File IDs as well, BTW.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .