Tracking moved files: An interesting tidbit on file references in OS X
Today I had to help someone with a problem with iTunes on Windows. For those of you that have not had the pleasure of using iTunes on Windows, it sucks, like most software written by Apple for Windows. That being said, this problem really had nothing to do with iTunes. The problem was that iTunes was 'losing' music. As it turns out, the music that the user saw as 'lost' turned out to have been moved from its original location (the desktop) to the 'Music' folder. iTunes uses absolute paths in its media library to hold reference to the file. When the file moves, the reference is broken, and thus, the music appears 'lost'. Without iTunes open all the time (and due to the occasionally unreliable file system watcher), it is simply not possible to track these files.
But then I started wondering... Surely Apple wouldn't let this happen on OSX. Details like this tend to be a place where Apple shines. So what in the world does iTunes do if I move something from the 'Music' folder to my 'Desktop' in OSX. I decided to try. First I closed iTunes, then I copied a music file, went back to iTunes, and hit play. Low and behold, it played, no problem. Not only did this leave me confused, but it also left me interested, so I decided to do a little exploring...
From what I can tell, Apple foresaw this problem with their 'aliases' early on in their original Mac OS, so rather than referencing files by path, you can reference files by a unique ID (if they are on a partition that uses a supported file system).
I'm no expert on Cocoa, but from what I can tell, the details of this can be found in the File Manager APIs and FSRef.
And for some more interesting reading on the topic.
So next time you get the dreaded 'cannot find the target to this shortcut, do you want to try to find the file?' prompt, just think about those 1980's Apple employees and how they solved this problem...