Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying and moving a symlink to another FS fails if the target is relative #189

Open
sskras opened this issue Jan 23, 2024 · 0 comments
Open
Labels

Comments

@sskras
Copy link

sskras commented Jan 23, 2024

This happens on a recently updated MSYS2:

$ uname -a
MSYS_NT-10.0-19044 DESKTOP-O7JE7JE 3.4.10.x86_64 2023-12-22 10:06 UTC x86_64 Msys

IOW, if after the operation a symlink would become broken (by target being relative), it won't cross the FS boundaries:

DEST_DIR=/tmp/destination
export DEST_DIR

echo The content > original
ln -sv original symlink-1
ln -sv original symlink-2
mkdir -pv ${DEST_DIR}

cp -Pv symlink-1 ${DEST_DIR}
mv -v symlink-2 ${DEST_DIR}

Actual output:

'symlink-1' -> 'original'
'symlink-2' -> 'original'
mkdir: created directory '/tmp/destination'
'symlink-1' -> '/tmp/destination/symlink-1'
cp: cannot create symbolic link '/tmp/destination/symlink-1': No such file or directory
copied 'symlink-2' -> '/tmp/destination/symlink-2'
mv: cannot create symbolic link '/tmp/destination/symlink-2': No such file or directory

A bit more verbose testing: https://asciinema.org/a/632681

If the destination dir is on the same FS, only copying is broken. Moving the symlink works fine:

'symlink-1' -> 'original'
'symlink-2' -> 'original'
mkdir: created directory '/tmp/destination'
'symlink-1' -> '/tmp/destination/symlink-1'
cp: cannot create symbolic link '/tmp/destination/symlink-1': No such file or directory
renamed 'symlink-2' -> '/tmp/destination/symlink-2'

Expected output:

'symlink-1' -> 'original'
'symlink-2' -> 'original'
mkdir: created directory '/tmp/destination'
'symlink-1' -> '/tmp/destination/symlink-1'
copied 'symlink-2' -> '/tmp/destination/symlink-2'
removed 'symlink-2'

If the target name is in an absolute format (IOW, it won't get broken after occurring in another dir), everything works across the FS just fine:

'symlink-1' -> '/D/bandom/original'
'symlink-2' -> '/D/bandom/original'
mkdir: created directory '/tmp/destination'
'symlink-1' -> '/tmp/destination/symlink-1'
copied 'symlink-2' -> '/tmp/destination/symlink-2'
removed 'symlink-2'

I tested that on fairly recent Cygwin too:

$ uname -a
CYGWIN_NT-10.0-19044 DESKTOP-O7JE7JE 3.4.10-1.x86_64 2023-11-29 12:12 UTC x86_64 Cygwin

It mostly works:

$ bash band.sh
'symlink-1' -> 'original'
'symlink-2' -> 'original'
mkdir: created directory '/tmp/destination'
'symlink-1' -> '/tmp/destination/symlink-1'
copied 'symlink-2' -> '/tmp/destination/symlink-2'
mv: listing attributes of 'symlink-2': Permission denied
removed 'symlink-2'

... with the following warning being added:

mv: listing attributes of '...': Permission denied

Please excuse me if this belongs to msys2/MSYS2-packages.

@lazka lazka added the symlinks label Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants