I have file paths in one side and their new paths where I want to duplicate them.
How to test whether they can be simply hardlinked or they should be copied?
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.
Step 1: Call link.
Step 2: If it returns -1 with
errnoset toEXDEV, then make a copy.[update]
In general, there is no portable (and reliable) way to answer this question. The closest you can get, I think, is to call statvfs for the source and destination and then compare the
f_fsidfields of the statvfs structures.Unfortunately, POSIX does not guarantee anything in particular about the
f_fsidfield. This test should work on Linux unless maybe you are asking about NFS-mounted filesystems…