Link to home
Start Free TrialLog in
Avatar of mliberi
mliberi

asked on

how to change last modification time of a symlink

I need to change last modification time of a symlink. I tried with 'utime' library call, but it follows symbolic link and change the inode.st_mtime field of the file the link is referring to.

Is there another call to change that field to the symlink itself?
If not, does anybody known a trick to do it?

I also read 'touch' man page. It does not have such a functionality.

thank you for your support.
Avatar of ahoffmann
ahoffmann
Flag of Germany image

touch can do it, but only as user root (not shure for links, this probably also depends on the underlaying shell)
Avatar of chris_calabrese
chris_calabrese

touch sits on top of utime, so if utime can't do it, then touch can't do it either.

What exactly is the problem you're trying to solve?  utime follows links because the folks who did links couldn't imagine a situation where anyone would care what the modification time of a link was.

The only way I know of to change the mod time of a link is to delete the link and recreate it.
Avatar of mliberi

ASKER

I'm trying to restore a saved symlink. I use lchown to restore uid and gid and I would expect a system call or C library call exist to set last modification time too.

Removing and recreating the link is not a solution because it sets current time, not a generic timestamp. Change current time for the time necessary to do that operation is not an accepted solution.
ASKER CERTIFIED SOLUTION
Avatar of chris_calabrese
chris_calabrese

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by chris_calabrese

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange