Warn when duplicating remote symlinks?

Advertisement

ekorn
Joined:
Posts:
3

Warn when duplicating remote symlinks?

I'm very grateful for the existence of WinSCP 8-)

However, today I got burned trying to backup a symlinked file via "Duplicate" (from the remote file's context menu). I expected this to work like a Linux command-line cp, which copies the contents of the symlink's target into a new file by default. It seems "Duplicate" works like cp --no-dereference, just making another symlink. Thus, changes to the duplicate affect the original file. So now I have no backup and two symlinks to a broken revision 8-P

I suggest that "Duplicate" offer an option whether to copy symlinks as symlinks, or at least a warning that this may not be what the user expects. (Copying a shortcut on Windows will copy the shortcut, so I it's not obvious what the default should be. However, I think I'm not alone in viewing Duplicate as synonymous with cp.)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: Warn when duplicating remote symlinks?

What protocol? What mode of duplication have you used? Direct or via local temporary copy?

Reply with quote

ekorn
Joined:
Posts:
3

Re: Warn when duplicating remote symlinks?

martin wrote:

What protocol?
SFTP (protocol 2, according to the saved settings).

martin wrote:

What mode of duplication have you used? Direct or via local temporary copy?
Direct; I see that it's fast even for large files. (WinSCP automatically starts another session to perform the command, if I understand correctly.)

Reply with quote

martin
Site Admin
martin avatar

Re: Warn when duplicating remote symlinks?

In that case WinSCP does cp -p -r -f. What would you suggest instead?

Reply with quote

ekorn
Joined:
Posts:
3

Re: Warn when duplicating remote symlinks?

martin wrote:

In that case WinSCP does cp -p -r -f. What would you suggest instead?
Thanks for the specifics. After some testing and googling, I found some details on the cp -r option:
By default, cp follows symbolic links only when not copying recursively. This default can be overridden with the --archive (-a), -d, --dereference (-L), --no-dereference (-P), and -H options. If more than one of these options is specified, the last one silently overrides the others.

By default, cp copies the contents of special files only when not copying recursively. This default can be overridden with the --copy-contents option.

So, for instance:
$ touch target.txt                                          # make a file
$ ln -s target.txt symlink_to_target.txt                    # symlink to it
$ cp symlink_to_target.txt cp_of_symlink_to_target.txt      # cp copies target
$ cp -r symlink_to_target.txt cp_r_of_symlink_to_target.txt # cp -r copies symlink
$ ls -l
-rw-r--r--  1 ...  0 Jan 12 13:39 cp_of_symlink_to_target.txt
lrwxrwxrwx  1 ... 10 Jan 12 13:41 cp_r_of_symlink_to_target.txt -> target.txt
lrwxrwxrwx  1 ... 10 Jan 12 13:39 symlink_to_target.txt -> target.txt
-rw-r--r--  1 ...  0 Jan 12 13:38 target.txt
I would suggest a warning prompt asking how to copy symlinks (with the usual "Do not show this message again" option to minimize the inconvenience). The decision might amount to setting one of the -adLPH options mentioned above, but I'm not familiar enough with them to know which one to use.

(Alternatively, the -r option might be omitted if the selection being Duplicate'd does not contain any directories. However, I suspect this would be at least as confusing as the current implementation.)

Thank you very much for your help.

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum