From 293c74ba79f0008f48073985507b34af59b45fa6 Mon Sep 17 00:00:00 2001 From: John Howard Date: Tue, 4 Jun 2019 13:38:52 -0700 Subject: [PATCH] Windows: Don't attempt detach VHD for R/O layers Signed-off-by: John Howard --- daemon/graphdriver/windows/windows.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/daemon/graphdriver/windows/windows.go b/daemon/graphdriver/windows/windows.go index 347231b104..9b83e7975b 100644 --- a/daemon/graphdriver/windows/windows.go +++ b/daemon/graphdriver/windows/windows.go @@ -338,11 +338,14 @@ func (d *Driver) Remove(id string) error { // If permission denied, it's possible that the scratch is still mounted, an // artifact after a hard daemon crash for example. Worth a shot to try detaching it // before retrying the rename. - if detachErr := vhd.DetachVhd(filepath.Join(layerPath, "sandbox.vhdx")); detachErr != nil { - return errors.Wrapf(err, "failed to detach VHD: %s", detachErr) - } - if renameErr := os.Rename(layerPath, tmpLayerPath); renameErr != nil && !os.IsNotExist(renameErr) { - return errors.Wrapf(err, "second rename attempt following detach failed: %s", renameErr) + sandbox := filepath.Join(layerPath, "sandbox.vhdx") + if _, statErr := os.Stat(sandbox); statErr == nil { + if detachErr := vhd.DetachVhd(sandbox); detachErr != nil { + return errors.Wrapf(err, "failed to detach VHD: %s", detachErr) + } + if renameErr := os.Rename(layerPath, tmpLayerPath); renameErr != nil && !os.IsNotExist(renameErr) { + return errors.Wrapf(err, "second rename attempt following detach failed: %s", renameErr) + } } } if err := hcsshim.DestroyLayer(d.info, tmpID); err != nil {