Archive for June, 2005

Ancient Wisdom

Saturday, June 18th, 2005

Chinese ProverbThe Tao Te Ching is an old book probably written in the sixth century by Lao Tsu. It is about ancient Chinese philosophy that says to accept what is in front of you without wanting it to be something else. Or simply put, just be.

There are many translations of the Tao Te Ching (only the Bible has been more frequently translated), but I chose the one by Gia-Fu Feng and Jane English. Along with the English translation, the book has typography of the original Chinese text set on beautiful black and white photographs.

On the right, I scanned in a verse that has particular salient meaning. If you are having trouble understanding it, try tilting your head sideways to the right.

Okay, maybe it didn’t really come from the book! :)

SymLeak

Wednesday, June 1st, 2005

Symbolic links, or just symlinks, are a nice way to link to a file or directory in the Unix file system. For example, you might install software in a directory called “fuzzy-wuzzy-1.2.3″ and then create a symlink called “fuzzy-wuzzy” that points to it. That way, you can just use the symlink, and when the software is upgraded, the same symlink can reference the new version.

But symlinks are an abstraction that make it seem like the same file or directory is in multiple places at once. When the abstraction is not complete, and it fails in a situation, it is said to “leak”. Let’s look at symlinks a little closer.

Let’s say you are migrating from fuzzy-wuzzy version 6 to version 7. The new version has many new features, so you decide to run both versions in parallel until the users can switch over. But there are some common files between the two, so instead of making copies of the common files, you use a symlink, like this:

/fuzzy-wuzzy-7/common -> /fuzzy-wuzzy-6/common

You have a symlink named “common” that lives under the directory “fuzzy-wuzzy-7″ and references the directory named “common” in “fuzzy-wuzzy-6″. Now, say you run these commands:

cd /fuzzy-wuzzy-7/common
cp datafile ..

You are trying to copy the file named “datafile” to the parent directory named “fuzzy-wuzzy-7″. But where do you suppose the file actually gets copied to? Yep, the file gets copied to the directory named “fuzzy-wuzzy-6″! Oops, you meant to modify version 7 and you accidently modified version 6! How awful of you. (I would never do something like this.)

While the “cd” and “pwd” commands respect the symlink, reporting a directory under version 7, you are really sitting in the version 6 “common” directory. And the “..” entry for that directory links to “fuzzy-wuzzy-6″.

So, the next time you want to use the “..” directory, remember that abstractions can leak, and absolute pathnames can sometimes be better. If you dislike the extra keystrokes, you can always use TAB (bash) or ESC-\ (ksh) to save some typing. Filename completion is your friend. Or, you can try to always be aware of parent directories that are symleaks, I mean, symlinks.