Six Colors
Six Colors

by Jason Snell & Dan Moren

This Week's Sponsor

Unite 5 - Turn Web Apps into Supercharged macOS apps

By Jason Snell

The (hard) link between Photos and iPhoto

Note: This story has not been updated for several years.

Screenshot 2015-02-10 12

[Updated April 9 to account for the final release of Photos for Mac. Also don’t miss our Photos FAQ.]

As I wrote my TidBITS article about the initial beta release of Photos for OS X, I was struck by how iPhoto imports work, which I described like this:

The Photos import process is friendly when it comes to disk space — it doesn’t duplicate the photos it imports from iPhoto and Aperture, so you don’t lose precious storage space.

What is this magic? How can it not duplicate the photos, yet not risk losing all your data if you were to throw away your old iPhoto library?

I had an inkling that this was all happening due to a feature of OS X that I believe has previously only been used by Apple in Time Machine, and prodded by TidBITS reader Bryan Walls, I confirmed it this morning. Photos uses Unix-style hard links when importing iPhoto libraries.

Mac users are probably more familiar with the concept of soft links, also known as “symbolic links.” Mac users would recognize the idea of a soft link from the long-time Mac concept of aliases1. In both of these cases, there’s something that looks like a file or folder/directory that’s actually just a reference to the real version of that file somewhere else in the filesystem.

Hard links aren’t like that. The best way to think of a hard link is that the contents of a file appear to exist in more than one location. If a file has two hard links, and you delete one, the file isn’t deleted—because it’s still linked to from another location.

That’s what the iPhoto import inside Photos does2: It creates hard links to the contents of your iPhoto library inside the Photos library. If you delete your iPhoto library, the files that were hard-linked from the Photos library still exist in the Photos library and aren’t deleted. For Mac users used to the a-file-is-a-file approach of the Finder, it’s a bit of a head-scratcher.

Time Machine uses this approach to create full backups while saving disk space. When you delete an old Time Machine backup, any files that are still hard-linked from subsequent backups remain intact. Any files that no longer have hard links elsewhere are deleted. iMovie apparently uses it, too, from time to time.

You can actually see if a file is hard-linked by using the Terminal. Before I imported my iPhoto library, here’s what an image deep inside the iPhoto library package looked like:

jsnell% ls -l
total 5968
-rw-r—r—@ 1 jsnell  staff  3054588 Jun 10  2013 WWDC13_0910.JPG

The 1 just before “jsnell staff” lists how many hard links exist to this particular file. One link, the one we’re looking at.

But after I import this iPhoto library into Photos, here’s what that same directory looks like:

jsnell% ls -l
total 5968
-rw-r—r—@ 2 jsnell  staff  3054588 Jun 10  2013 WWDC13_0910.JPG

Now there are two. To find the location of the two links, I find the unique ID of the file in question:

jsnell% ls -li
total 5968
10652722 -rw-r—r—@ 2 jsnell  staff  3054588 Jun 10  2013 WWDC13_0910.JPG

And then another Terminal command shows me where those two links are:

jsnell% find /Users/jsnell -inum 10652722

/Users/jsnell/Desktop/An iPhoto Library.migratedphotolibrary/Masters/2015/02/10/20150210-110352/WWDC13_0910.JPG

/Users/jsnell/Desktop/An Photos Library.photoslibrary/Masters/2015/02/10/20150210-110352/WWDC13_0910.JPG

This reveals two interesting facts.

  • When Photos migrates an iPhoto library, it changes the file extension on the iPhoto library package to .migratedphotolibrary.3
  • On import, Photos makes a hard link to all iPhoto media assets in its own library package, using the same directory structure as iPhoto.

So what happens if you edit one of those files? Something very clever, it turns out: If I open the JPEG image from the migrated iPhoto library in Photoshop, edit it, and save it, that version is indeed altered—but the version in the Photos library is untouched. Basically, modifying that file causes the link between the two versions to break. They’re different, and no longer connected.

I can also confirm that Photos is pretty comprehensive when it comes to its iPhoto import. Both Albums and Smart Albums are imported, and the Smart Albums remain “smart.” Smart Albums based on deprecated data like star ratings still work—since star ratings are converted to keywords, Smart Albums based on star ratings are converted to search for the equivalent star keywords. Descriptions, titles, flags, and geotagging from iPhoto are all picked up as well, and iPhoto Events are imported as Albums.

If you’ve edited a photo in iPhoto before importing, Photos will display that edited version—but the original has also imported behind the scenes, so you can revert back to it if you need to.

  1. Pedantic note: OS X aliases are not the same as unix symbolic links. But in general terms they do more or less the same thing: connect a “real” file to a separate representation of it. 
  2. It doesn’t seem to do this when you just drag images into Photos—in that case, it copies a version of the photo into its own Photos Library package. 
  3. It also uses the iPhoto library’s name as the basis for the imported Photos library’s name, which is why my “An iPhoto Library” was imported as the amusingly wrong “An Photos Library.” 

If you appreciate articles like this one, support us by becoming a Six Colors subscriber. Subscribers get access to an exclusive podcast, members-only stories, and a special community.

Search Six Colors