Skip to main content
added 1004 characters in body
Source Link

Hardlink creation on directories would be unrevertable. Suppose we have :

/dir1 ├──this.txt ├──directory │ └──subfiles └──etc 

I hardlink it to /dir2.

So /dir2 now also contains all these files and directories

What if I change my mind? I can't just rmdir /dir2 (because it is non empty)

And if I recursively deletes in /dir2... it will be deleted from /dir1 too!

IMHO it's a largely sufficient reason to avoid this!

Edit :

Comments suggest removing the directory by doing rm on it. But rm on a non-empty directory fails, and this behaviour must remain, whether the directory is hardlinked or not. So you can't just rm it to unlink. It would require a new argument to rm, just to say "if the directory inode has a reference count > 1, then only unlink the directory".

Which, in turns, break another principle of least surprise : it means that removal of a directory hardlink I just created is not the same as removal of a normal file hardlink...

I will rephrase my sentence : Without further development, hardlink creation would be unrevertable (as no current command could handle the removal without being incoherent with current behaviour)

If we allow more development to handle the case, the number of pitfalls, and the risk of data loss if you're not enough aware of how the system works, such a development implies, is IMHO a sufficient reason to restrict hardlinking on directories.

Hardlink creation on directories would be unrevertable. Suppose we have :

/dir1 ├──this.txt ├──directory │ └──subfiles └──etc 

I hardlink it to /dir2.

So /dir2 now also contains all these files and directories

What if I change my mind? I can't just rmdir /dir2 (because it is non empty)

And if I recursively deletes in /dir2... it will be deleted from /dir1 too!

IMHO it's a largely sufficient reason to avoid this!

Hardlink creation on directories would be unrevertable. Suppose we have :

/dir1 ├──this.txt ├──directory │ └──subfiles └──etc 

I hardlink it to /dir2.

So /dir2 now also contains all these files and directories

What if I change my mind? I can't just rmdir /dir2 (because it is non empty)

And if I recursively deletes in /dir2... it will be deleted from /dir1 too!

IMHO it's a largely sufficient reason to avoid this!

Edit :

Comments suggest removing the directory by doing rm on it. But rm on a non-empty directory fails, and this behaviour must remain, whether the directory is hardlinked or not. So you can't just rm it to unlink. It would require a new argument to rm, just to say "if the directory inode has a reference count > 1, then only unlink the directory".

Which, in turns, break another principle of least surprise : it means that removal of a directory hardlink I just created is not the same as removal of a normal file hardlink...

I will rephrase my sentence : Without further development, hardlink creation would be unrevertable (as no current command could handle the removal without being incoherent with current behaviour)

If we allow more development to handle the case, the number of pitfalls, and the risk of data loss if you're not enough aware of how the system works, such a development implies, is IMHO a sufficient reason to restrict hardlinking on directories.

Use a code block with tree-style formatting for clarity
Source Link

Hardlink creation on directories would be unrevertable. Suppose we have :

  • /dir1
    • this(.txt)
    • directory
    • have
    • files
    • and
    • directories/
/dir1 ├──this.txt ├──directory │ └──subfiles └──etc 

I hardlink it to /dir2/dir2.

So /dir2/dir2 now also contains all these files and directories

What if I change my mind  ? I can't just rmdir /dir2rmdir /dir2 (because it is non empty)

And if I recursively deletes in /dir2/dir2... it will be deleted from /dir1/dir1 too  !

IMHO it's a largely sufficient reason to avoid this  !

Hardlink creation on directories would be unrevertable. Suppose we have :

  • /dir1
    • this(.txt)
    • directory
    • have
    • files
    • and
    • directories/

I hardlink it to /dir2.

So /dir2 now also contains all these files and directories

What if I change my mind  ? I can't just rmdir /dir2 (because it is non empty)

And if I recursively deletes in /dir2... it will be deleted from /dir1 too  !

IMHO it's a largely sufficient reason to avoid this  !

Hardlink creation on directories would be unrevertable. Suppose we have :

/dir1 ├──this.txt ├──directory │ └──subfiles └──etc 

I hardlink it to /dir2.

So /dir2 now also contains all these files and directories

What if I change my mind? I can't just rmdir /dir2 (because it is non empty)

And if I recursively deletes in /dir2... it will be deleted from /dir1 too!

IMHO it's a largely sufficient reason to avoid this!

Source Link

Hardlink creation on directories would be unrevertable. Suppose we have :

  • /dir1
    • this(.txt)
    • directory
    • have
    • files
    • and
    • directories/

I hardlink it to /dir2.

So /dir2 now also contains all these files and directories

What if I change my mind ? I can't just rmdir /dir2 (because it is non empty)

And if I recursively deletes in /dir2... it will be deleted from /dir1 too !

IMHO it's a largely sufficient reason to avoid this !