From 07cefb98e40090c82daa6d722d5e57f4fceba4b7 Mon Sep 17 00:00:00 2001 From: danishprakash Date: Mon, 3 Apr 2023 17:11:18 +0530 Subject: [PATCH] copier: retain symlink target w/ follow-link Signed-off-by: danishprakash --- copier/copier.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 }