[Q] creating hard links for Directories

well as we all know the File class in ruby has the method link which
creates a hard link between files. I want to create hard links between
directories. so a link to directory would have the same content and any
change to its content will effect the other linked directories... I tries
using FileUtils class but it didn't work!.. any ideas?

What OS are you working with? I don't believe the Linux VFS allows this. AFAIK, hard links between directories will confuse fsck. For example, where would ".." point?

-Jeff

···

On Sep 29, 2005, at 9:21 PM, kraf001 wrote:

well as we all know the File class in ruby has the method link which
creates a hard link between files. I want to create hard links between
directories. so a link to directory would have the same content and any
change to its content will effect the other linked directories... I tries
using FileUtils class but it didn't work!.. any ideas?

Use a symbolic link instead.

Hard links for directories are not supported by any Unix/Linux/Posix file
system that I'm aware of. The main problem is that it allows cycles to
be created in the file system directory structure and that confuses the
hell out of most people and tools.

I don't know but I suspect that the same restriction applies to various
Windows and MacOS file systems.

Gary Wright

···

On Sep 29, 2005, at 9:21 PM, kraf001 wrote:

well as we all know the File class in ruby has the method link which
creates a hard link between files. I want to create hard links between
directories. so a link to directory would have the same content and any
change to its content will effect the other linked directories... I tries
using FileUtils class but it didn't work!.. any ideas?

As pointed out, this is probably OS dependant, but under unix like operating
systems, you can't make a hard link to a directory. This is to prevent the
directory structure from becoming cyclic.

Are you sure that a symbolic (soft) link won't do for what you're trying to
acomplish? If you make changes to directories under a link, it will make
changes under the "real" directory.

···

On Sep 29, 2005, at 9:21 PM, kraf001 wrote:

> well as we all know the File class in ruby has the method link which
> creates a hard link between files. I want to create hard links between
> directories. so a link to directory would have the same content and
> any
> change to its content will effect the other linked directories... I
> tries
> using FileUtils class but it didn't work!.. any ideas?
>

--
Lou

well the problem is when I use symbolic links, it gives me a new directory
with a file in it... this file has the same name as the direcoty I was
trying to link... but the direcotry created doesn't have the same content
of the linked directory!

How are you calling this? Here's an example that might help:

You have a directory you want to link...

ljs@kontiki ~/foo
$ ls -l
total 0
drwxr-xr-x 2 ljs ljs 192 2005-09-30 08:19 bar

with some files in it...

ljs@kontiki ~/foo
$ ls -l bar
total 24
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file0
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file1
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file2

use the 'File.symlink' method to create the link...

ljs@kontiki ~/foo
$ ruby -e 'File.symlink("bar","baz")'

and the link is created.

ljs@kontiki ~/foo
$ ls -l
total 0
drwxr-xr-x 2 ljs ljs 192 2005-09-30 08:19 bar
lrwxrwxrwx 1 ljs ljs 3 2005-09-30 08:23 baz -> bar

The original directory is there...

ljs@kontiki ~/foo
$ ls -l bar
total 24
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file0
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file1
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file2

and the new link points to it.

ljs@kontiki ~/foo
$ ls -lH baz
total 24
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file0
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file1
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file2

Create a new file under the link:

ljs@kontiki ~/foo
$ echo data > baz/new_file

and it goes into the orignal directory

ljs@kontiki ~/foo
$ ls -l bar
total 28
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file0
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file1
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:18 file2
-rw-r--r-- 1 ljs ljs 5 2005-09-30 08:23 new_file

file can be referenced from the orignal path

ljs@kontiki ~/foo
$ cat bar/new_file
data

It should also work the other way around.

Hope this was helpful and not overly long winded or pedantic. Also I hope
this pertains to your OS: This was run on Ubuntu Hoary.

···

On 9/30/05, kraf001 <ihaveblackout@yahoo.com> wrote:

well the problem is when I use symbolic links, it gives me a new directory
with a file in it... this file has the same name as the direcoty I was
trying to link... but the direcotry created doesn't have the same content
of the linked directory!

--
Lou