Skip to content

Commit fbdfc6b

Browse files
committed
chunked ApplyDiff(): track implicitly-created directories in layers
When applying a chunked diff, ApplyDiff() iterates through the entries in the diff's table of contents, creating directories and other zero-length items like empty files, symbolic links, and directories, building a queue of hard links, and asking goroutines to locate files in other layers and configured OSTree repositories which contain content that matches what should eventually end up in non-zero-length files in the layer. If a file's entire contents couldn't be found locally, but it was split into chunks in the chunked diff, ApplyDiff() then searches for the chunks in local layers. Lastly, the contents of files with non-zero lengths, which ApplyDiff() had attempted to find locally, but which weren't found locally, are then requested from the registry. Track which directories in the layer are created implicitly by ApplyDiff(), so that the overlay driver can reset their ownership, permissions, extended attributes, and datestamps to match the immediately lower layer, if there is one. Signed-off-by: Nalin Dahyabhai <[email protected]>
1 parent 2a0c3c2 commit fbdfc6b

File tree

4 files changed

+255
-126
lines changed

4 files changed

+255
-126
lines changed

drivers/driver.go

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ type DriverWithDifferOutput struct {
188188
Metadata string
189189
BigData map[string][]byte
190190
TarSplit []byte
191+
ImplicitDirs []string
191192
TOCDigest digest.Digest
192193
}
193194

drivers/overlay/overlay.go

+43
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,49 @@ func (d *Driver) ApplyDiffFromStagingDirectory(id, parent, stagingDirectory stri
20842084
return err
20852085
}
20862086

2087+
lowerDiffDirs, err := d.getLowerDiffPaths(id)
2088+
if err != nil {
2089+
return err
2090+
}
2091+
if len(lowerDiffDirs) > 0 {
2092+
backfiller := unionbackfill.NewBackfiller(options.Mappings, lowerDiffDirs)
2093+
for _, implicitDir := range diffOutput.ImplicitDirs {
2094+
hdr, err := backfiller.Backfill(implicitDir)
2095+
if err != nil {
2096+
return err
2097+
}
2098+
if hdr == nil {
2099+
continue
2100+
}
2101+
path := filepath.Join(stagingDirectory, implicitDir)
2102+
idPair := idtools.IDPair{UID: hdr.Uid, GID: hdr.Gid}
2103+
if options.Mappings != nil {
2104+
if mapped, err := options.Mappings.ToHost(idPair); err == nil {
2105+
idPair = mapped
2106+
}
2107+
}
2108+
if err := os.Chown(path, idPair.UID, idPair.GID); err != nil {
2109+
return err
2110+
}
2111+
for xattr, xval := range hdr.Xattrs {
2112+
if err := system.Lsetxattr(path, xattr, []byte(xval), 0); err != nil {
2113+
return err
2114+
}
2115+
}
2116+
if err := os.Chmod(path, os.FileMode(hdr.Mode)&os.ModePerm); err != nil {
2117+
return err
2118+
}
2119+
atime := hdr.AccessTime
2120+
mtime := hdr.ModTime
2121+
if atime.IsZero() {
2122+
atime = mtime
2123+
}
2124+
if err := os.Chtimes(path, atime, mtime); err != nil {
2125+
return err
2126+
}
2127+
}
2128+
}
2129+
20872130
diffOutput.UncompressedDigest = diffOutput.TOCDigest
20882131

20892132
return os.Rename(stagingDirectory, diffPath)

pkg/chunked/internal/compression.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type FileMetadata struct {
4848
ChunkDigest string `json:"chunkDigest,omitempty"`
4949
ChunkType string `json:"chunkType,omitempty"`
5050

51-
// internal: computed by mergeTOCEntries.
51+
// internal: computed by mergeTocEntries.
5252
Chunks []*FileMetadata `json:"-"`
5353
}
5454

0 commit comments

Comments
 (0)