How do I copy a symbolic link (and not the file it points to) in a Perl program while preserving all of the symbolic link attributes (such as owner and permissions)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Perl you can use the
readlink()function to find out the destination of a symlink.You can also use the
lstat()function to read the permissions of the symlink (as opposed tostat()which will read the details of the file pointed to by the symlink).Actually setting the ownership on the new symlink can’t be done without extra help as Perl doesn’t expose the
lchown()system call. For that you can use the PerlLchownmodule from CPAN.Assuming sufficient permissions (nb: unchecked code)
You don’t need to worry about the permissions on the symlink – they always appear as
-rwxrwxrwx