I was packaging a gcc cross-compiler together with the sys-root of the target system. That sys-root contained a lot of symlinks, sometimes targeting files outside of the package (such as /etc/_whatever_). Conan packages this without complaining. However this created an error at
conan installtime with an access violation when trying to set some properties (timestamps?) on the _target_ of these packages (which conan shouldn't be modifying anyway as they are outside of the package). You may want to
create another problem report for this specific issue.
_Originally posted by @michiel-dewilde in https://github.com/conan-io/conan/pull/4051#issuecomment-447270855_
Probably checking always all the files to see if they belong to the package is costly. We could provide a tool maybe? how the files were packaged? by conan or by an external install? I don't know if the conan copy could check links pointing out of the package.
IIRC the FileCopier class already clears the broken symlinks but I am not sure if it takes the outside symlinks into account
Maybe this can be a pre/post_package hook, what do you think?
Did a small test and the FileCopier is copying the symlink correctly but it does not take into account that the "outside links" have to be copied too:
def test_outside_link_copy(self):
folder1 = temp_folder()
sub1 = os.path.join(folder1, "subdir1")
sub2 = os.path.join(folder1, "subdir2")
file1_path = os.path.join(sub1, "file1.txt")
file2_path = os.path.join(sub1, "file2.c")
save(file1_path, "file1")
save(file2_path, "file2")
os.makedirs(sub2)
os.symlink(file1_path, os.path.join(sub2, "file_subdir1_symlink.txt"))
folder2 = temp_folder()
copier = FileCopier(sub2, folder2)
copier("*", links=True)
self.assertEqual(os.listdir(folder2), ["file1.txt", "file2.c"])
However, I think this is the right behavior as we don't know if the user is doing this on purpose or not (for example in the case of a conanfile used to mimic a System package).
The most we could do is provide a tool for this, bu I think the user should be responsible for taking care of the symlinks on what they is trying to achieve
That's the reason I was suggesting a hook. Maybe we can provide an implementation that warns about links outside a package (traverse the packaged directory checking for links outside it), the user can activate/deactivate it, or even modify it to raise an error instead of a warning.
Agree. I have opened an issue in the hooks repo https://github.com/conan-io/hooks/issues/14
I think it is enough to close this one
Most helpful comment
Agree. I have opened an issue in the hooks repo https://github.com/conan-io/hooks/issues/14
I think it is enough to close this one