Skip to content

Commit c28137b

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 e88c997 commit c28137b

File tree

5 files changed

+256
-127
lines changed

5 files changed

+256
-127
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
@@ -1955,6 +1955,49 @@ func (d *Driver) ApplyDiffFromStagingDirectory(id, parent, stagingDirectory stri
19551955
return err
19561956
}
19571957

1958+
lowerDiffDirs, err := d.getLowerDiffPaths(id)
1959+
if err != nil {
1960+
return err
1961+
}
1962+
if len(lowerDiffDirs) > 0 {
1963+
backfiller := unionbackfill.NewBackfiller(options.Mappings, lowerDiffDirs)
1964+
for _, implicitDir := range diffOutput.ImplicitDirs {
1965+
hdr, err := backfiller.Backfill(implicitDir)
1966+
if err != nil {
1967+
return err
1968+
}
1969+
if hdr == nil {
1970+
continue
1971+
}
1972+
path := filepath.Join(stagingDirectory, implicitDir)
1973+
idPair := idtools.IDPair{UID: hdr.Uid, GID: hdr.Gid}
1974+
if options.Mappings != nil {
1975+
if mapped, err := options.Mappings.ToHost(idPair); err == nil {
1976+
idPair = mapped
1977+
}
1978+
}
1979+
if err := os.Chown(path, idPair.UID, idPair.GID); err != nil {
1980+
return err
1981+
}
1982+
for xattr, xval := range hdr.Xattrs {
1983+
if err := system.Lsetxattr(path, xattr, []byte(xval), 0); err != nil {
1984+
return err
1985+
}
1986+
}
1987+
if err := os.Chmod(path, os.FileMode(hdr.Mode)&os.ModePerm); err != nil {
1988+
return err
1989+
}
1990+
atime := hdr.AccessTime
1991+
mtime := hdr.ModTime
1992+
if atime.IsZero() {
1993+
atime = mtime
1994+
}
1995+
if err := os.Chtimes(path, atime, mtime); err != nil {
1996+
return err
1997+
}
1998+
}
1999+
}
2000+
19582001
diffOutput.UncompressedDigest = diffOutput.TOCDigest
19592002

19602003
return os.Rename(stagingDirectory, diff)

pkg/chunked/cache_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (c *layersCache) load() error {
109109
}
110110

111111
bigData, err := c.store.LayerBigData(r.ID, cacheKey)
112-
// if the cache areadly exists, read and use it
112+
// if the cache already exists, read and use it
113113
if err == nil {
114114
defer bigData.Close()
115115
metadata, err := readMetadataFromCache(bigData)

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)