1

Is there a way to use traditional commands to update a symlink when it's older than the original file?

I use a Seafile server (similar to Dropbox) to make certain files available to my students. So I shared a directory and created links to those files. Both Seafile and Dropbox don't care about links and copy the actual files to the server.

The problem is that if I update the actual file, the link timestamp doesn't change and the new version of the file is not uploaded to the server.

I tried the trivial test:

[ ./shared/the-symlink -ot ./actualfiles/pontedfile ] && touch -h ./shared/the-symlink

Unfortunately, test dereferences the link and the timestamp of the file is compared to itself, what results false, of course.

Note also that the symlink must be newer than the linked file. I don't need it to be set to the same timestamp.

Is there a way to test check the timestamp of the link instead of the pointed file?

Other solutions I'm trying to avoid:

  • Copying the files instead of linking would work, but I'd have to consume too much disk space because the files are usually large;
  • touching all symlinks would also works, but all the files would be copyied to the server again and again; (not a problem: see edit below)

I'm willing a more elegant solution than converting the timestamps to string and comparing them by my own...

This thead is not a solution for me.

Edit:

This is not an answer to the question, but it's a solution for my problem: touch -h * updates all symlinks timestamps. Seafile recognizes the change and takes action. Fornunately, it re-checks now using the actual file timestamp and upload only the files that changed.

Edit2:

The solution using stat works: stat -c "%Y". Thanks to steve.

  • 1
    That works @steve. – Jander Aug 7 at 11:35
0

stat will give the timestamp of the symlink itself.

So an approach such as below would work

[[ $(stat -c '%Y' b) -lt $(stat -c '%Y' a) ]] && touch .......

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.