@@ -23,8 +23,11 @@ import (
2323 "os"
2424 "path/filepath"
2525 "strings"
26+ "syscall"
2627
28+ "github.com/Microsoft/go-winio/pkg/bindfilter"
2729 "github.com/Microsoft/hcsshim"
30+ "golang.org/x/sys/windows"
2831)
2932
3033const sourceStreamName = "containerd.io-source"
@@ -45,7 +48,7 @@ func (m *Mount) mount(target string) error {
4548 }
4649
4750 if m .Type == "bind" {
48- if err := ApplyFileBinding (target , m .Source , readOnly ); err != nil {
51+ if err := bindfilter . ApplyFileBinding (target , m .Source , readOnly ); err != nil {
4952 return fmt .Errorf ("failed to bind-mount to %s: %w" , target , err )
5053 }
5154 return nil
@@ -89,12 +92,12 @@ func (m *Mount) mount(target string) error {
8992 return fmt .Errorf ("failed to get volume path for layer %s: %w" , m .Source , err )
9093 }
9194
92- if err = ApplyFileBinding (target , volume , readOnly ); err != nil {
95+ if err = bindfilter . ApplyFileBinding (target , volume , readOnly ); err != nil {
9396 return fmt .Errorf ("failed to set volume mount path for layer %s: %w" , m .Source , err )
9497 }
9598 defer func () {
9699 if err != nil {
97- RemoveFileBinding (target )
100+ bindfilter . RemoveFileBinding (target )
98101 }
99102 }()
100103
@@ -128,29 +131,7 @@ func (m *Mount) GetParentPaths() ([]string, error) {
128131
129132// Unmount the mount at the provided path
130133func Unmount (mount string , flags int ) error {
131- var err error
132134 mount = filepath .Clean (mount )
133- // This should expand paths like ADMINI~1 and PROGRA~1 to long names.
134- mount , err = getFinalPath (mount )
135- if err != nil {
136- return fmt .Errorf ("fetching real path: %w" , err )
137- }
138- mounts , err := GetBindMappings (mount )
139- if err != nil {
140- return fmt .Errorf ("fetching bind mappings: %w" , err )
141- }
142- found := false
143- for _ , mnt := range mounts {
144- if mnt .MountPoint == mount {
145- found = true
146- break
147- }
148- }
149- if ! found {
150- // not a mount point
151- return nil
152- }
153-
154135 adsFile := mount + ":" + sourceStreamName
155136 var layerPath string
156137
@@ -162,7 +143,11 @@ func Unmount(mount string, flags int) error {
162143 layerPath = string (layerPathb )
163144 }
164145
165- if err := RemoveFileBinding (mount ); err != nil {
146+ if err := bindfilter .RemoveFileBinding (mount ); err != nil {
147+ if errno , ok := errors .Unwrap (err ).(syscall.Errno ); ok && errno == windows .ERROR_INVALID_PARAMETER {
148+ // not a mount point
149+ return nil
150+ }
166151 return fmt .Errorf ("removing mount: %w" , err )
167152 }
168153
0 commit comments