Page 1 of 1

How do you show hard links only?

Posted: Thu Apr 24, 2008 10:19 pm
by alex.barylski
I'm confused about how hard linsk work exactly...

I have a source directory with files in it. I then made a exact mirror of all the directories using mkdir recursively. However the file contents are hard links in all the mirrored copies.

Essentially as I understand it, each hard link points to a source or original file. If the source is removed do all the hard links break or is this only the case with soft links?

Hard links are pointers to contents and a reference counting mechanism is used to detemrine when file data is removed, this I understand. So if I create a file normally it's data is already stored as a hard link and adding additional hard links just increments the counter?

Basically, if I have several files which hard link to a source, either of those edited files will be reflected through any of the other 'aliases' so to speak.

How can I tell if the file I'm editing is a hardlink or a physical copy of the original -- that is if modified it creates a branch as opposed to updating multiple copies simulatneously???

Cheers :)

Re: How do you show hard links only?

Posted: Thu Apr 24, 2008 10:51 pm
by VladSun
Hockey wrote:If the source is removed do all the hard links break or is this only the case with soft links?
Only for soft links.
Hockey wrote:So if I create a file normally it's data is already stored as a hard link and adding additional hard links just increments the counter?
Yes
Hockey wrote:How can I tell if the file I'm editing is a hardlink or a physical copy of the original -- that is if modified it creates a branch as opposed to updating multiple copies simulatneously???
There are no "copies"... think about hardlinks as C++ references, and softlinks as pointers.

PS: Please, don't use hardlinks - they are dangerous.

Re: How do you show hard links only?

Posted: Fri Apr 25, 2008 12:00 am
by alex.barylski
Hmmm...why are hard links dangerous?

Basically I have a source tree which I develop on, test, etc.

I then have copies of that source tree installed in various places for several clients. Instead of having to update each file in each separate installation what I have done is create hardlinks for each file (not directories -- just files) to essentially point to the original source, so when I make a change to the original, it's propagated throughout the other installations as well.

So your saying i should use soft links for this instead? Why?

Re: How do you show hard links only?

Posted: Fri Apr 25, 2008 12:54 am
by VladSun
Well, *now* I'm not sure that they are dangerous ... they would be if you could create a hard link to a directory. But I tried it and it appears that it's not permitted :)

Also, don't foget to turn on FollowSymlinks in httpd.conf ;)

PS: Or even better SymLinksIfOwnerMatch

Re: How do you show hard links only?

Posted: Fri Apr 25, 2008 1:13 am
by alex.barylski
As I understand, hard links cannot be used on directories, but I don't understand why that would be dangerous? Because of recursion?
Also, don't foget to turn on FollowSymlinks in httpd.conf
Hmmm...I don't use symlinks...but just curious...why?

I guess one could maybe use a symlink to gain access to private file through apache this way??? Is this what the concern would be about?

Re: How do you show hard links only?

Posted: Fri Apr 25, 2008 1:24 am
by VladSun
Hockey wrote:As I understand, hard links cannot be used on directories, but I don't understand why that would be dangerous? Because of recursion?
For example, imagine that you created you created a hard link to a directory inside itself, and then removed the link to that directory from its parent directory. The garbage collector wouldn't see that the directory can't be accessed, since it still has links to it, but you'll be unable to remove it, since you can't access it by any name.
Hockey wrote:Hmmm...I don't use symlinks...but just curious...why?

I guess one could maybe use a symlink to gain access to private file through apache this way??? Is this what the concern would be about?
First, I do advice you to use soft links.
And if you use soft links you'll have to turn FollowSymlinks/SymLinksIfOwnerMatch on in order to have access to linked files/directories by Apache.

Read the Apache manual about the security issues of FollowSymlinks/SymLinksIfOwnerMatch :)

Re: How do you show hard links only?

Posted: Fri Apr 25, 2008 1:53 am
by Kieran Huggins
That's a neat idea, but why not just use SVN? Then you could test away without fear of production systems breaking. An "svn up" in the client machines is quick and easy, and you also get the benefit of version control.

Re: How do you show hard links only?

Posted: Fri Apr 25, 2008 5:24 am
by VladSun
Using SVN (and co.) would be like "client side" sync, while using soft links would be like "server-push" sync :)