Wednesday, June 01, 2005

CVS and hard linking

Current music: Pedro the Lion - Simple Economics

Geek talk... go!

Don't try creating hardlinked files which you are going to use with CVS.

Here is a little background. On *nix file systems you can create one file and be able to access the file from two locations. There are two ways of doing this... One is a symbolic link, and the other is a hardlink.

A symlink is a new file which actually just refers to the file you want. A hardlink is different. It creates a new entry in the filesystem inode table so that there are two entries which refer to the same inode. Therefore, when you change one of the files, they both change... This is because really, they are the same inode (where the data is stored on the harddrive is the same physical location).

I had a great idea. I have a CVS playpen and I wanted the files in that playpen to build under a different directory. I symlinked the directory and tried to do a make from the new symlink. This did not work. When the linker tried to find the libraries in a directory above it, it failed because it looked in a directory above the real file, not the symlink. Doh!

So a new great idea was to create hardlinked files where I wanted to build. Now it built, but when I checked in the playpen in CVS it did something strange. The files were now not hardlinked anymore. It appeared that the files had been deleted and recreated, but this causes the files to be in a different inode. This makes it weird... CVS gets the updates, but then the next time you change the files which are in the build directory, the files in the playpen don't get altered.

Solution: Create the entire directory structure you want in the build directory, then only symlink the files, not the directory structure.

No comments: