fs_extra
fs_extra copied to clipboard
Add option to transform symbolic links on copy
I would like to see a special copy option to transform symbolic links using absolute file paths to symbolic links relative to another path. The reason I am looking for such an option is that I am working on a tool to create sysroots for the purpose of cross-compiling based on the contents of docker containers (https://github.com/devolutions/albatross-rs). Just like chroot environments, the absolute symbolic links inside the docker container will not work when copied as-is for usage outside of the container.
For instance, if I copy the contents of a 32-bit Linux container, I get symbolic links like this: /this-is-my-new-sysroot-dir/usr/lib/i386-linux-gnu/libz.so -> /lib/i386-linux-gnu/libz.so.1.2.11 where /lib/i386-linux-gnu/libz.so.1.2.11 is obviously something that only exists relative to the root of the original file system contained in the docker container. The same issue occurs with trying to copy files from a chroot for usage on the host.
The easiest way to work around the issue would be to provide the old root and modify all symbolic links to relative links (libz.so -> libz.so.1.2.11, no absolute path). Another option would be to simply "rebase" all symbolic links to another absolute path based on where the files will be copied, but I would rather go with the relative symbolic links option.
I like your idea :+1: It's really interesting. I think better will be developed both methods for work. Maybe even add third method when we can use unique ids, not a paths of old root.
@awakecoding i begin work in this ticket and found it's work in a current moment like second offer approach. And i remember, when i begin work this lib, i decided to use this approach. But i'm still want to make options for copy symlink. but you can already use copy symbolic files and folders.
Hey, I think I might need this feature asked 5 years ago 😅
My problem is that the symbolic link is not copied to the new directory.
Reproduction guide
mkdir aaa
cd aaa
touch mario
ln -s mario luigi
and then run this rust program:
use fs_extra::dir;
fn main() {
fs_extra::dir::copy("aaa", "bbb", &dir::CopyOptions::default()).unwrap();
}
Actual behavior
$ cd bbb/aaa
$ ls -alrS
total 0
-rw-r--r--@ 1 marcoieni staff 0 Jun 7 22:12 mario
-rw-r--r--@ 1 marcoieni staff 0 Jun 7 22:12 luigi
drwxr-xr-x 3 marcoieni staff 96 Jun 7 22:16 ..
drwxr-xr-x@ 4 marcoieni staff 128 Jun 7 22:16 .
Expected behavior
$ cd bbb/aaa
$ ls -alrS
total 0
-rw-r--r--@ 1 marcoieni staff 0 Jun 7 22:12 mario
lrwxr-xr-x@ 1 marcoieni staff 5 Jun 7 22:33 luigi -> mario
drwxr-xr-x 3 marcoieni staff 96 Jun 7 22:16 ..
drwxr-xr-x@ 4 marcoieni staff 128 Jun 7 22:33 .
Request
Is there a way to get this behavior? I didn't get it from your last comment.