-2

I noticed that when I create relative symbolic links, starting the source path with ./ keeps it that way and starting with an alphanumeric character keeps it that way, despite them both meaning the same thing. Both kinds act identically in every case I can think of, but there must be a reason why the developers chose to add this seemingly unnecessary redundancy; perhaps there are edge cases where one would behave differently from the other.

7
  • 2
    Why do you think anybody had to add any redundancy? This could simply be a result of how pathname resolution works in the first place.
    – muru
    Apr 18 at 18:35
  • @muru Good point. But my more general question remains.
    – ATLief
    Apr 18 at 18:37
  • 1
    This isn't redundancy. This is simply "do exactly what the user told us to do, and don't try to second-guess them by looking for redundancies which will only slow down the program 99.999% of the time it's run."
    – John
    Apr 18 at 18:51
  • 1
    Of course, there's the case you sidestepped by saying "alphanumeric character" - filenames beginning with a - are significantly different in behaviour
    – muru
    Apr 18 at 19:03
  • 1
    Why should the developers put in a check to see if you linked ./foo/bar instead of foo/bar? The relative path is the same so should they second-guess your intent?
    – doneal24
    Apr 18 at 19:22

1 Answer 1

2

Creating a symbolic link only stores the target as a string, no attempt is made to resolve the link at all. There are several reasons for this; one is that a symbolic link can be created pointing to a file which may exist later (because it will be created later, or because it will appear later, e.g. through a new mounted file system); another is that symbolic links can be used to reference data which isn’t a file at all (on Linux, look at the links under /proc/*/fd — you’ll see some pointing to pipes, sockets, deleted files etc.).

The target of a symbolic link is explicitly specified to be a string, stored as-is. It is only interpreted when a program attempts to open the symbolic link as if it’s a file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.