Pārlūkot izejas kodu

Fix docker cp dir with hard link

docker run --name=test ubuntu /bin/sh -c "cd /tmp && echo hi > a && ln a b" && docker cp test:/tmp tmp_
test
link /root/tmp/a /root/tmp_/b: no such file or directory

Signed-off-by: yangshukui <yangshukui@huawei.com>
yangshukui 8 gadi atpakaļ
vecāks
revīzija
d58ffa0364
1 mainītis faili ar 3 papildinājumiem un 0 dzēšanām
  1. 3 0
      pkg/archive/copy.go

+ 3 - 0
pkg/archive/copy.go

@@ -332,6 +332,9 @@ func RebaseArchiveEntries(srcContent io.Reader, oldBase, newBase string) io.Read
 			}
 			}
 
 
 			hdr.Name = strings.Replace(hdr.Name, oldBase, newBase, 1)
 			hdr.Name = strings.Replace(hdr.Name, oldBase, newBase, 1)
+			if hdr.Typeflag == tar.TypeLink {
+				hdr.Linkname = strings.Replace(hdr.Linkname, oldBase, newBase, 1)
+			}
 
 
 			if err = rebasedTar.WriteHeader(hdr); err != nil {
 			if err = rebasedTar.WriteHeader(hdr); err != nil {
 				w.CloseWithError(err)
 				w.CloseWithError(err)