Skip to content

Commit

Permalink
overlay: use directly MkdirAllAndChownNew
Browse files Browse the repository at this point in the history
use MkdirAllAndChownNew instead of checking for the directory
existence first and then create it if missing.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Aug 21, 2024
1 parent 57a4177 commit 05df80e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -1463,12 +1463,11 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
}

mergedDir := d.getMergedDir(id, dir, inAdditionalStore)
// Attempt to create the merged dir only if it doesn't exist.
if err := fileutils.Exists(mergedDir); err != nil && os.IsNotExist(err) {
if err := idtools.MkdirAllAs(mergedDir, 0o700, rootUID, rootGID); err != nil && !os.IsExist(err) {
return "", err
}
// Attempt to create the merged dir if it doesn't exist, but don't chown an already existing directory (it might be in an additional store)
if err := idtools.MkdirAllAndChownNew(mergedDir, 0o700, idtools.IDPair{UID: rootUID, GID: rootGID}); err != nil && !os.IsExist(err) {
return "", err
}

if count := d.ctr.Increment(mergedDir); count > 1 {
return mergedDir, nil
}
Expand Down

0 comments on commit 05df80e

Please sign in to comment.