@@ -1238,6 +1238,47 @@ func (d *Driver) parseStorageOpt(storageOpt map[string]string, driver *Driver) e
12381238 return nil
12391239}
12401240
1241+ func (d * Driver ) dir (id string ) string {
1242+ p , _ , _ := d .dir2 (id , false )
1243+ return p
1244+ }
1245+
1246+ func (d * Driver ) getAllImageStores () []string {
1247+ additionalImageStores := d .AdditionalImageStores ()
1248+ if d .imageStore != "" {
1249+ additionalImageStores = append ([]string {d .imageStore }, additionalImageStores ... )
1250+ }
1251+ return additionalImageStores
1252+ }
1253+
1254+ // homeDirForImageStore returns the home directory to use when an image store is configured
1255+ func (d * Driver ) homeDirForImageStore () string {
1256+ if d .imageStore != "" {
1257+ return path .Join (d .imageStore , d .name )
1258+ }
1259+ // If there is not an image store configured, use the same
1260+ // store
1261+ return d .home
1262+ }
1263+
1264+ func (d * Driver ) dir2 (id string , useImageStore bool ) (string , string , bool ) {
1265+ homedir := d .home
1266+ if useImageStore {
1267+ homedir = d .homeDirForImageStore ()
1268+ }
1269+ newpath := path .Join (homedir , id )
1270+ if err := fileutils .Exists (newpath ); err != nil {
1271+ for _ , p := range d .getAllImageStores () {
1272+ l := path .Join (p , d .name , id )
1273+ err = fileutils .Exists (l )
1274+ if err == nil {
1275+ return l , homedir , true
1276+ }
1277+ }
1278+ }
1279+ return newpath , homedir , false
1280+ }
1281+
12411282// getLowerForParent returns the contents of lowerFile for a child layer of parent.
12421283//
12431284// This should only be used to construct a lowerFile for compatibility;
@@ -1303,47 +1344,8 @@ func (d *Driver) getLowerLayerIDs(id string) ([]string, error) {
13031344 }
13041345}
13051346
1306- func (d * Driver ) dir (id string ) string {
1307- p , _ , _ := d .dir2 (id , false )
1308- return p
1309- }
1310-
1311- func (d * Driver ) getAllImageStores () []string {
1312- additionalImageStores := d .AdditionalImageStores ()
1313- if d .imageStore != "" {
1314- additionalImageStores = append ([]string {d .imageStore }, additionalImageStores ... )
1315- }
1316- return additionalImageStores
1317- }
1318-
1319- // homeDirForImageStore returns the home directory to use when an image store is configured
1320- func (d * Driver ) homeDirForImageStore () string {
1321- if d .imageStore != "" {
1322- return path .Join (d .imageStore , d .name )
1323- }
1324- // If there is not an image store configured, use the same
1325- // store
1326- return d .home
1327- }
1328-
1329- func (d * Driver ) dir2 (id string , useImageStore bool ) (string , string , bool ) {
1330- homedir := d .home
1331- if useImageStore {
1332- homedir = d .homeDirForImageStore ()
1333- }
1334- newpath := path .Join (homedir , id )
1335- if err := fileutils .Exists (newpath ); err != nil {
1336- for _ , p := range d .getAllImageStores () {
1337- l := path .Join (p , d .name , id )
1338- err = fileutils .Exists (l )
1339- if err == nil {
1340- return l , homedir , true
1341- }
1342- }
1343- }
1344- return newpath , homedir , false
1345- }
1346-
1347+ // getLowerDirs returns a list of lower directories for a layer id;
1348+ // the directories may be symbolic links (do not call redirectDiffIfAdditionalLayer).
13471349func (d * Driver ) getLowerDirs (id string ) ([]string , error ) {
13481350 lowerLayerIDs , err := d .getLowerLayerIDs (id )
13491351 if err != nil {
@@ -1357,6 +1359,22 @@ func (d *Driver) getLowerDirs(id string) ([]string, error) {
13571359 return lowersArray , nil
13581360}
13591361
1362+ // getLowerDiffPaths returns a list of lower diff paths for a layer id;
1363+ // the paths have redirectDiffIfAdditionalLayer applied.
1364+ func (d * Driver ) getLowerDiffPaths (id string ) ([]string , error ) {
1365+ layers , err := d .getLowerDirs (id )
1366+ if err != nil {
1367+ return nil , err
1368+ }
1369+ for i , l := range layers {
1370+ layers [i ], err = redirectDiffIfAdditionalLayer (l , false )
1371+ if err != nil {
1372+ return nil , err
1373+ }
1374+ }
1375+ return layers , nil
1376+ }
1377+
13601378func (d * Driver ) optsAppendMappings (opts string , uidMaps , gidMaps []idtools.IDMap ) string {
13611379 if uidMaps != nil {
13621380 var uids , gids bytes.Buffer
@@ -2419,20 +2437,6 @@ func (d *Driver) getDiffPath(id string) (string, error) {
24192437 return redirectDiffIfAdditionalLayer (path .Join (dir , "diff" ), false )
24202438}
24212439
2422- func (d * Driver ) getLowerDiffPaths (id string ) ([]string , error ) {
2423- layers , err := d .getLowerDirs (id )
2424- if err != nil {
2425- return nil , err
2426- }
2427- for i , l := range layers {
2428- layers [i ], err = redirectDiffIfAdditionalLayer (l , false )
2429- if err != nil {
2430- return nil , err
2431- }
2432- }
2433- return layers , nil
2434- }
2435-
24362440// DiffSize calculates the changes between the specified id
24372441// and its parent and returns the size in bytes of the changes
24382442// relative to its base filesystem directory.
0 commit comments