>>Hi,
>>I recently came across a situation wherein an effort has to be made
>>to change the modification time of the symbolic link (NOT the file
>>that it points to!) to a different time other than the current time.
>>utimes() / touch changes the file being pointed to ...
>The problem with what you are trying to do is that a symbolic link shares
>an inode with the original link. and the inode contains the date
>information. In order to change the modification time of a link, the
>link must have its own inode. This translates into a "hard" link.
>Sorry but you cannot change the modification time on a symbolic link
>without changing the inode, which changes all links to that inode.
Actually, that's not true -- you've got the definition of symbolic link
and hard link confused. In a hard link, the same inode is linked into
more than one directory on the filesystem. In a symbolic link, a new
special file (with its own i-node of type S_IFLNK) is created, and that
special file gives a (partial or complete) pathname to another file,
which most system calls (except lstat()) automagically interpret as the
file linked to, not the link itself.
For example, witness the following sequence of commands, typed on
SunOS 4.1.3:
$ cd /tmp
$ date > foo
$ ln -s foo bar
$ ls -li
total 6
33809 lrwxrwxrwx 1 logan 3 Nov 7 20:25 bar -> foo
33808 -rw-r--r-- 1 logan 29 Nov 7 20:25 foo
$ cat bar
Tue Nov 7 20:25:02 PST 1995
$ cat foo
Tue Nov 7 20:25:02 PST 1995
$ exit
Notice that "bar" and "foo" have separate i-node numbers. (See the
first column in the output of "ls -li".)
Anyway, the reason you can't change stuff about the symbolic link is
that the functions which operate on the file automagically expand the
symbolic link into the file to which it refers before doing the
requested operation. So, in the above example, if you want to set the
modification date of "bar", you do a 'utimes ("/tmp/bar", NULL)'. The
utimes() call (or some other system thingy) translates the "/tmp/bar"
into (effectively) "/tmp/foo" and blithely does the operation on it.
In other words, what you need is an lutimes() call, just like there
is an lstat() call in addition to stat().
Incidentally, I think I remember coming across a Unix which behaves the
other way by default -- it changes the link's time rather than the file
linked to. However, I don't remember which kind of Unix that was.
Hope this helps...
- Logan
--
=-- do not send me any junk e-mail --=