OS X filesystem madness

So most of last week I spent working on a few bugs in the Catalog Builder, a web-based application I wrote with a few other people at Staples.

The particular bug I was working on was seemingly impossible to fix, and it was driving me to the point of madness. I had it fixed on my local machine, but when I would copy that change to the test server, it wouldn’t work.

Thursday I was determined to fix it once and for all. I stayed at work until around 10 or 11pm, but finally went home in failure, near tears of frustration for not being able to fix it.

The next morning, my manager Asha sat next to me while I once again copied my change from my local machine to the test server. It still didn’t work. Then she had me do it one more time, and miraculously, it WORKED!

I chalked it up to exhaustion, figured I must have made a mistake on Thursday night, copied the wrong file up to the server or something.

But today, I thought about it – I had been very careful on Thursday night. There had to be some other reason that my good code seemed bad on the server. My first conjecture was that there was some issue with the directory names.

I did some poking around, and figured it out.

There is something really odd about the way Mac OS X treats symbolic links.

A symbolic link is a “fake” directory or file, that is actually a pointer to a real file. This is useful if you need a certain file or directory to appear to be in several places, while in fact it’s only in one place. This is better than making multiple copies of the file or directory, because if you have to make changes to it, you only have to change it in one place, since symbolic links just point to the original path the file or directory is in.

Which is the important point.

in Unix, a symbolic link is a marker that points to a path. If you “cd” (change directory) to the symbolic link, it goes to the path indicated.

On Mac, an alias is a marker that points to a folder. If you click on the alias, it goes to the folder indicated.

The difference arises if you move the target directory.

The symbolic link points to the path, so it would say the target dir is missing.
the alias points to the folder, so it would still open the folder, even if it were moved.

And the real trouble is that OS X treats a symbolic link BOTH ways. When you create a symbolic link in the command line, it does TWO things. It creates a unix symbolic link, but also creates an alias in the GUI.

In the GUI, the alias will point to the original FOLDER no matter where you move it. In command line or via webserver, it is a symbolic link, and points to the original PATH.

So when I moved the original folder to the trash, then replaced it with a new folder with the same name as the old one, I would go through the GUI to update the files, then through the webserver to view it… but going through the GUI I was updating the files in the trash (new path, old folder), while viewing the files was showing the ones in the original path (old path, new folder)…

It was this inconsistency that drove me to the point of madness on Thursday.

One thought on “OS X filesystem madness”

  1. Whoa! That sounds unbelievably frustrating. Good thing you didn’t have a wrench nearby to throw. Computers can be quirky little beasts at times. Only as logical as the programmers who put them together, I’m afraid. Glad it finally worked though.

    Love J.

Comments are closed.