From 0441674005fa75b0e97d68bd0d162d7f5470882e Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Mon, 11 Mar 2024 13:55:02 +0100 Subject: [PATCH] overlay: create the merged path only if it does not exist follow-up for ccb70a79a69a1a5137ff24720520534bfbcc2316 more information here: https://github.com/containers/storage/issues/1827#issuecomment-1988332922 Signed-off-by: Giuseppe Scrivano --- drivers/overlay/overlay.go | 8 +++++--- tests/overlay-recreate.bats | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/overlay/overlay.go b/drivers/overlay/overlay.go index f007aa9437..ac3edcfd33 100644 --- a/drivers/overlay/overlay.go +++ b/drivers/overlay/overlay.go @@ -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.IsExist(err) { + if err := idtools.MkdirAs(mergedDir, 0o700, rootUID, rootGID); err != nil { + return "", err + } } if count := d.ctr.Increment(mergedDir); count > 1 { return mergedDir, nil diff --git a/tests/overlay-recreate.bats b/tests/overlay-recreate.bats index 038a48810a..c3ebbb3297 100644 --- a/tests/overlay-recreate.bats +++ b/tests/overlay-recreate.bats @@ -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 @@ -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.