You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into two problems related to copying symlinks: one is if the destination already exists, and one is if the resolved destination does not exist. (Both problems are distinct but closely related; in my case, attempting to fix one in my fork revealed the other... and caused a bunch of tests to fail, of course.)
In onLink, if the resolvedSrc and resolvedDest are the same, the copy should be considered successful rather than throwing an error (consistent behavior with cp --preserve=links (cp -r on MacOS)). A consequence of this is that calling e.g. fse.copySync(src, dest) twice in a row throws if src is a directory containing a symlink somewhere inside its hierarchy, but otherwise works fine if there are no symlinks.
In onLink, the line (destStat === notExist) incorrectly checks for the resolved destination, which means that the following line (return fs.symlinkSync(resolvedSrc, dest)) can fail if dest exists but resolvedDest does not. That's because destStat is obtained from checkPaths/checkStats, which does not honor the opts.dereference option, i.e. uses stat rather than lstat.
Yes, it still doesn't work (I actually tested on master).
However, now I'm somewhat confused.
While setting up a local test "fixture", I found out that on macOS, the behaviour is not what I would expect: when recursively copying a directory, symlinks (whether broken or not) cannot overwrite a target symlink even when identical, and no amount of -f fixes this:
Existing target directory symlinks are treated as directories and you get an error saying you're trying to copy a non-directory element on top of a directory (e.g. cp: cannot overwrite directory dest/dirlink with non-directory src/dirlink)
Existing target file symlinks are equally not overwritable, with a different error message: cp: symlink: foo: File exists
While it would be nice to have it behave as I expected, it would deviate from what the OS shell itself does, so we can probably just close this Issue.
Mac OS High Sierra 10.13.6
8.11.3
fs-extra
version:7.0.0
I ran into two problems related to copying symlinks: one is if the destination already exists, and one is if the resolved destination does not exist. (Both problems are distinct but closely related; in my case, attempting to fix one in my fork revealed the other... and caused a bunch of tests to fail, of course.)
In
onLink
, if theresolvedSrc
andresolvedDest
are the same, the copy should be considered successful rather than throwing an error (consistent behavior withcp --preserve=links
(cp -r
on MacOS)). A consequence of this is that calling e.g.fse.copySync(src, dest)
twice in a row throws ifsrc
is a directory containing a symlink somewhere inside its hierarchy, but otherwise works fine if there are no symlinks.In
onLink
, the line(destStat === notExist)
incorrectly checks for the resolved destination, which means that the following line (return fs.symlinkSync(resolvedSrc, dest)
) can fail ifdest
exists butresolvedDest
does not. That's becausedestStat
is obtained fromcheckPaths
/checkStats
, which does not honor theopts.dereference
option, i.e. usesstat
rather thanlstat
.Related: #638
The text was updated successfully, but these errors were encountered: