go.mod: github.com/Microsoft/hcsshim v0.10.0-rc.7

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda
2023-03-07 21:48:06 +09:00
parent c77ddf5381
commit da1ffdd757
17 changed files with 483 additions and 12 deletions

View File

@@ -51,6 +51,8 @@ func ExportLayerToTar(ctx context.Context, w io.Writer, path string, parentLayer
}
func writeTarFromLayer(ctx context.Context, r wclayer.LayerReader, w io.Writer) error {
linkRecords := make(map[[16]byte]string)
t := tar.NewWriter(w)
for {
select {
@@ -76,6 +78,27 @@ func writeTarFromLayer(ctx context.Context, r wclayer.LayerReader, w io.Writer)
return err
}
} else {
numberOfLinks, fileIDInfo, err := r.LinkInfo()
if err != nil {
return err
}
if numberOfLinks > 1 {
if linkName, ok := linkRecords[fileIDInfo.FileID]; ok {
// We've seen this file before, by another name, so put a hardlink in the tar stream.
hdr := backuptar.BasicInfoHeader(name, 0, fileInfo)
hdr.Mode = 0644
hdr.Typeflag = tar.TypeLink
hdr.Linkname = linkName
if err := t.WriteHeader(hdr); err != nil {
return err
}
continue
}
// All subsequent names for this file will be hard-linked to this name
linkRecords[fileIDInfo.FileID] = filepath.ToSlash(name)
}
err = backuptar.WriteTarFileFromBackupStream(t, r, name, size, fileInfo)
if err != nil {
return err