@@ -31,7 +31,6 @@ import (
3131
3232 "github.com/Microsoft/go-winio"
3333 winfs "github.com/Microsoft/go-winio/pkg/fs"
34- "github.com/Microsoft/go-winio/vhd"
3534 "github.com/Microsoft/hcsshim"
3635 "github.com/Microsoft/hcsshim/computestorage"
3736 "github.com/Microsoft/hcsshim/pkg/ociwclayer"
@@ -256,11 +255,19 @@ func (s *snapshotter) Remove(ctx context.Context, key string) error {
256255 return err
257256 }
258257 // If permission denied, it's possible that the scratch is still mounted, an
259- // artifact after a hard daemon crash for example. Worth a shot to try detaching it
258+ // artifact after a hard daemon crash for example. Worth a shot to try deactivating it
260259 // before retrying the rename.
261- if detachErr := vhd .DetachVhd (filepath .Join (path , "sandbox.vhdx" )); detachErr != nil {
262- return errors .Wrapf (err , "failed to detach VHD: %s" , detachErr )
260+ var (
261+ home , layerID = filepath .Split (path )
262+ di = hcsshim.DriverInfo {
263+ HomeDir : home ,
264+ }
265+ )
266+
267+ if deactvateErr := hcsshim .DeactivateLayer (di , layerID ); deactvateErr != nil {
268+ return errors .Wrapf (err , "failed to deactivate layer following failed rename: %s" , deactvateErr )
263269 }
270+
264271 if renameErr := os .Rename (path , renamed ); renameErr != nil && ! os .IsNotExist (renameErr ) {
265272 return errors .Wrapf (err , "second rename attempt following detach failed: %s" , renameErr )
266273 }
@@ -461,7 +468,7 @@ func (s *snapshotter) createScratchLayer(ctx context.Context, snDir string, pare
461468 return nil
462469}
463470
464- // convertScratchToReadOnlyLayer reimporst the layer over itself, to transfer the files from the sandbox.vhdx to the on-disk storage.
471+ // convertScratchToReadOnlyLayer reimports the layer over itself, to transfer the files from the sandbox.vhdx to the on-disk storage.
465472func (s * snapshotter ) convertScratchToReadOnlyLayer (ctx context.Context , snapshot storage.Snapshot , path string ) (retErr error ) {
466473
467474 // TODO darrenstahlmsft: When this is done isolated, we should disable these.
0 commit comments