Dynamic link to a file that moves

xjarty

Cadet
Joined
Jan 31, 2021
Messages
8
Hello all you smart people, ;)

I'm trying to do something custom with the filesystem, and I'm hitting roadblocks. I'm hoping you can suggest solutions?

I have a file, let's call it somepath/somefile.txt
I want to create a link to this file that keeps working even if the file changes path or name:
  1. Create linktofile.link -> somepath/somefile.txt
  2. File gets moved, renamed: somepath_new/somefile_new.txt
  3. Link is seamlessly auto-updated: linktofile.link -> somepath_new/somefile_new.txt

I've thought of a few solutions, but none are great:
  1. Use a symbolic link: links don't follow when the file is renamed or moved
  2. Create a primary key for each file, encode it in the filename, and write code to find the key in the filesystem. Will technically work, but not great. Mangles my filenames, risk that I might accidentally delete the PK from the filename.
  3. Encode a primary key in the extended attributes, and write code to find the key across the filesystem. I can't find a good "find" tool for the xattrs. I could write code to iterate over every file in the system and check its xattrs for the PK, but I imagine this would be very slow.

Is there a standard way to solve this problem? If not, is there a hacky way to solve it? :D

I'm open to any suggestions, thanks!
 
Joined
Oct 22, 2019
Messages
3,641
Why not just use hardlinks?
 
Top