diff --git a/copier/copier.go b/copier/copier.go index 7bfbf9d1ac9..854b0144999 100644 --- a/copier/copier.go +++ b/copier/copier.go @@ -1307,7 +1307,14 @@ func copierHandlerGet(bulkWriter io.Writer, req request, pm *fileutils.PatternMa // cases where this was a symlink that we // dereferenced, be sure to use the name of the // link. - if err := copierHandlerGetOne(info, "", filepath.Base(queue[i]), item, req.GetOptions, tw, hardlinkChecker, idMappings); err != nil { + + // If following link, pass symlink target for + // the link to be generated on the destination. + var symlinkTarget string + if req.GetOptions.NoDerefSymlinks && info.Mode()&os.ModeType == os.ModeSymlink { + symlinkTarget = item + } + if err := copierHandlerGetOne(info, symlinkTarget, filepath.Base(queue[i]), item, req.GetOptions, tw, hardlinkChecker, idMappings); err != nil { if req.GetOptions.IgnoreUnreadable && errorIsPermission(err) { continue }