Apparently, what touch(1) uses internally is utimensat(2). I haven't found anything on CPAN yet* that directly supports what you want to do, but in theory, you could use FFI::Platypus to link to it. Time::HiRes's utime does use utimensat, but doesn't support setting the AT_SYMLINK_NOFOLLOW flag needed to modify the symlink instead of the file it points to.
* Update: See here.
| [reply] [d/l] [select] |
It seems such an option is not present in File::Touch. I can't find it in any other module, either (but my CPAN searching skills are below average, I usually can't even find a module I've used).
But what you want is easy to implement using plain Perl functions: instead of touching the old symlink, create a new one and rename it over the old one:
#! /usr/bin/perl
use strict;
use warnings;
use File::Touch qw{ touch };
sub show_stat {
system qw( stat file link );
}
unlink qw( file link new_link );
touch('file');
symlink 'file', 'link';
show_stat();
sleep 1;
symlink 'file', 'new_link';
rename new_link => 'link';
show_stat();
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [d/l] [select] |
Your example sets the atime/mtime to current time. I need to set the atime and mtime of the link to a specific value. I updated my question to be more clear.
| [reply] |
| [reply] |
My guess is that touch -h is using the lutimes(3) system call (where available) which a quick ripgrep through the perl source doesn't show any reference to. You theoretically could wrap it directly yourself with Inline::C but I don't think you're otherwise going to have luck directly from perl.
Edit: derp, wrong man section fixed
The cake is a lie.
The cake is a lie.
The cake is a lie.
| [reply] [d/l] [select] |
| [reply] [d/l] [select] |
My distant memory is that if you check the time of a file that is referenced by a symbolic link, you get the time of the referenced file, not the link. I really don't know what happens if you try to modify the time, but you might need to de-reference it to the target file. | [reply] |