logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

"File::lchown" - modify attributes of symlinks without dereferencing them

Author

       Paul Evans <leonerd@leonerd.org.uk>

perl v5.40.1                                       2025-06-23                                  File::lchown(3pm)

Description

       The regular "chown" system call will dereference a symlink and apply ownership changes to the file at
       which it points. Some OSes provide system calls that do not dereference a symlink but instead apply their
       changes directly to the named path, even if that path is a symlink (in much the same way that "lstat"
       will return attributes of a symlink rather than the file at which it points).

Functions

$count=lchown$uid,$gid,@paths
       Set the new user or group ownership of the specified paths, without dereferencing any symlinks. Passing
       the value -1 as either the $uid or $gid will leave that attribute unchanged. Returns the number of files
       successfully changed.

   $count=lutimes$atime,$mtime,@paths
       Set the access and modification times on the specified paths, without dereferencing any symlinks. Passing
       "undef" as both $atime and $mtime will update the times to the current system time.

       Note that for both "lchown" and "lutimes", if more than one path is given, if later paths succeed after
       earlier failures, then the value of $! will not be reliable to indicate the nature of the failure. If you
       wish to use $! to report on failures, make sure only to pass one path at a time.

Name

       "File::lchown" - modify attributes of symlinks without dereferencing them

See Also

lchown(2) - change ownership of a file

       •   lutimes(2) - change file timestamps

Synopsis

        use File::lchown qw( lchown lutimes );

        lchown $uid, $gid, $linkpath or die "Cannot lchown() - $!";

        lutimes $atime, $mtime, $linkpath or die "Cannot lutimes() - $!";

Todo

       •   Implement  sub-second precision on "lutimes", most likely by taking floats or two-element ARRAY refs,
           similar to "Time::HiRes" uses.

See Also