Skip to content

Commit

Permalink
Merge pull request #1858 from giuseppe/create-merged-only-if-it-doesn…
Browse files Browse the repository at this point in the history
…ot-exist

overlay: create the merged path only if it does not exist
  • Loading branch information
openshift-merge-bot[bot] authored Mar 11, 2024
2 parents 853cc6a + 846f78a commit 8fbdbaa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -1666,9 +1666,11 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
}

mergedDir := path.Join(dir, "merged")
// Create the driver merged dir
if err := idtools.MkdirAs(mergedDir, 0o700, rootUID, rootGID); err != nil && !os.IsExist(err) {
return "", err
// Attempt to create the merged dir only if it doesn't exist.
if _, err := os.Stat(mergedDir); err != nil && os.IsNotExist(err) {
if err := idtools.MkdirAs(mergedDir, 0o700, rootUID, rootGID); err != nil && !os.IsExist(err) {
return "", err
}
}
if count := d.ctr.Increment(mergedDir); count > 1 {
return mergedDir, nil
Expand Down
5 changes: 4 additions & 1 deletion tests/overlay-recreate.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ load helpers
storage unmount "$lowerlayer"
storage mount "$midlayer"
storage unmount "$midlayer"
storage mount "$upperlayer"
run storage --debug=false mount "$upperlayer"
merged_dir="$output"
storage unmount "$upperlayer"
# okay, but how about this?
rm -v ${TESTDIR}/root/overlay/*/link
Expand All @@ -27,6 +28,8 @@ load helpers
storage unmount "$lowerlayer"
storage mount "$midlayer"
storage unmount "$midlayer"
# check it works if we delete the merged directory.
rmdir "$merged_dir"
storage mount "$upperlayer"
storage unmount "$upperlayer"
# okay, not bad, kid.
Expand Down

0 comments on commit 8fbdbaa

Please sign in to comment.