Skip to content

Commit d9fa957

Browse files
committed
Move all the "lower"-related functions to single place.
Only moves unchanged code, should not change behavior. Also document the difference between getLowerDirs and getLowerDiffPaths. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
1 parent 440f02f commit d9fa957

1 file changed

Lines changed: 44 additions & 40 deletions

File tree

storage/drivers/overlay/overlay.go

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,32 +1218,6 @@ func (d *Driver) parseStorageOpt(opts *graphdriver.CreateOpts, readOnly bool) (q
12181218
return res, nil
12191219
}
12201220

1221-
// getLowerForParent returns the contents of lowerFile for a child layer of parent.
1222-
//
1223-
// This should only be used to construct a lowerFile for compatibility;
1224-
// new code should rely on lowerLayersFile instead.
1225-
func (d *Driver) getLowerForParent(parent string) (string, error) {
1226-
parentDir := d.dir(parent)
1227-
1228-
// Ensure parent exists
1229-
if err := fileutils.Lexists(parentDir); err != nil {
1230-
return "", err
1231-
}
1232-
1233-
parentLink, err := os.ReadFile(path.Join(parentDir, "link"))
1234-
if err != nil {
1235-
return "", err
1236-
}
1237-
lowers := []string{path.Join(linkDir, string(parentLink))}
1238-
1239-
parentLower, err := os.ReadFile(path.Join(parentDir, lowerFile))
1240-
if err == nil {
1241-
parentLowers := strings.SplitSeq(string(parentLower), ":")
1242-
lowers = slices.AppendSeq(lowers, parentLowers)
1243-
}
1244-
return strings.Join(lowers, ":"), nil
1245-
}
1246-
12471221
func (d *Driver) dir(id string) string {
12481222
p, _, _ := d.dir2(id, false)
12491223
return p
@@ -1285,6 +1259,32 @@ func (d *Driver) dir2(id string, useImageStore bool) (string, string, bool) {
12851259
return newpath, homedir, false
12861260
}
12871261

1262+
// getLowerForParent returns the contents of lowerFile for a child layer of parent.
1263+
//
1264+
// This should only be used to construct a lowerFile for compatibility;
1265+
// new code should rely on lowerLayersFile instead.
1266+
func (d *Driver) getLowerForParent(parent string) (string, error) {
1267+
parentDir := d.dir(parent)
1268+
1269+
// Ensure parent exists
1270+
if err := fileutils.Lexists(parentDir); err != nil {
1271+
return "", err
1272+
}
1273+
1274+
parentLink, err := os.ReadFile(path.Join(parentDir, "link"))
1275+
if err != nil {
1276+
return "", err
1277+
}
1278+
lowers := []string{path.Join(linkDir, string(parentLink))}
1279+
1280+
parentLower, err := os.ReadFile(path.Join(parentDir, lowerFile))
1281+
if err == nil {
1282+
parentLowers := strings.SplitSeq(string(parentLower), ":")
1283+
lowers = slices.AppendSeq(lowers, parentLowers)
1284+
}
1285+
return strings.Join(lowers, ":"), nil
1286+
}
1287+
12881288
// getLowerLayerIDs returns a list of lower layer IDs for a layer id;
12891289
// typically the contents of lowerLayersFile, falling back to lowerFile.
12901290
// If the layer has neither of the files, returns an empty list without reporting an error.
@@ -1320,6 +1320,8 @@ func (d *Driver) getLowerLayerIDs(id string) ([]string, error) {
13201320
}
13211321
}
13221322

1323+
// getLowerDirs returns a list of lower directories for a layer id;
1324+
// the directories may be symbolic links (do not call redirectDiffIfAdditionalLayer).
13231325
func (d *Driver) getLowerDirs(id string) ([]string, error) {
13241326
lowerLayerIDs, err := d.getLowerLayerIDs(id)
13251327
if err != nil {
@@ -1333,6 +1335,22 @@ func (d *Driver) getLowerDirs(id string) ([]string, error) {
13331335
return lowersArray, nil
13341336
}
13351337

1338+
// getLowerDiffPaths returns a list of lower diff paths for a layer id;
1339+
// the paths have redirectDiffIfAdditionalLayer applied.
1340+
func (d *Driver) getLowerDiffPaths(id string) ([]string, error) {
1341+
layers, err := d.getLowerDirs(id)
1342+
if err != nil {
1343+
return nil, err
1344+
}
1345+
for i, l := range layers {
1346+
layers[i], err = redirectDiffIfAdditionalLayer(l, false)
1347+
if err != nil {
1348+
return nil, err
1349+
}
1350+
}
1351+
return layers, nil
1352+
}
1353+
13361354
func (d *Driver) optsAppendMappings(opts string, uidMaps, gidMaps []idtools.IDMap) string {
13371355
if uidMaps != nil {
13381356
var uids, gids bytes.Buffer
@@ -2395,20 +2413,6 @@ func (d *Driver) getDiffPath(id string) (string, error) {
23952413
return redirectDiffIfAdditionalLayer(path.Join(dir, "diff"), false)
23962414
}
23972415

2398-
func (d *Driver) getLowerDiffPaths(id string) ([]string, error) {
2399-
layers, err := d.getLowerDirs(id)
2400-
if err != nil {
2401-
return nil, err
2402-
}
2403-
for i, l := range layers {
2404-
layers[i], err = redirectDiffIfAdditionalLayer(l, false)
2405-
if err != nil {
2406-
return nil, err
2407-
}
2408-
}
2409-
return layers, nil
2410-
}
2411-
24122416
// DiffSize calculates the changes between the specified id
24132417
// and its parent and returns the size in bytes of the changes
24142418
// relative to its base filesystem directory.

0 commit comments

Comments
 (0)