0

I think I understand what soft and hard symbolic links are, but I'm not sure how programs access them (as opposed to me, a user).

For example, I want to replace my ~/.bashrc with a symbolic link that resides elsewhere. When I as a user open this file, say in Vim, really I'm editing ~/some/path/.bashrc (regardless the type of link). That's good and all, but what about programs? For example an installer that appends to ~/.bashrc?

  1. Can programs open a file in either "mode"—following a symlink or not? My guess is that file handles in programming languages compile or interpret such that they refer to an inode, so with hardlinks at least, they always follow.

  2. If softlinks can be opened in either mode, what does that look like in a major programming language?

  3. If programs are "blind" to symbolic links, then is it safe to assume I can softlink ~/.bashrc to ~/some/path/.bashrc and expect it to work with no hitches ever, provided that the file exists and retains the same permissions as the original ~/.bashrc? Or is there some weird scenario that can break its function?

I have read

and other answers that explain the difference between a soft and hardlink, but more knowledge about symbolic links doesn't make me feel confident in this regard.

Andrew Cheong
  • 673
  • 2
  • 9
  • 23
  • 3
    a common method of "atomic write" is writing to a temporary file then moving it, overwriting the destination (which would break a symlink) – Fox Sep 20 '20 at 10:21
  • @Fox - Ah, so actually that's what `git pull` would do too, so either direction of symlinking would break when pulling down a remote change, if I'm correct. I guess then there can't be a solution that doesn't re-create those links (_e.g._ via a git hook). I'm still curious about how languages handle files though, so keeping this question open. – Andrew Cheong Sep 20 '20 at 10:47
  • Many editors do that too... – Stephen Kitt Sep 20 '20 at 10:57
  • Many "security" type programs regard soft links of configuration files as an attempt to deceive. Hard links are just a counter in an inode. Finding out the other hardlinks is difficult. – waltinator Sep 20 '20 at 16:31

0 Answers0