@@ -23,7 +23,6 @@ import (
2323 "os"
2424 "path/filepath"
2525 "syscall"
26- "time"
2726
2827 "github.com/opencontainers/runtime-spec/specs-go"
2928)
@@ -161,63 +160,9 @@ func fixLongPath(path string) string {
161160 return string (pathbuf [:w ])
162161}
163162
164- // ensureRemoveAll wraps `os.RemoveAll` to check for specific errors that can
165- // often be remedied.
166- // Only use `ensureRemoveAll` if you really want to make every effort to remove
167- // a directory.
168- //
169- // Because of the way `os.Remove` (and by extension `os.RemoveAll`) works, there
170- // can be a race between reading directory entries and then actually attempting
171- // to remove everything in the directory.
172- // These types of errors do not need to be returned since it's ok for the dir to
173- // be gone we can just retry the remove operation.
174- //
175- // This should not return a `os.ErrNotExist` kind of error under any circumstances
163+ // ensureRemoveAll is a wrapper for os.RemoveAll on Windows.
176164func ensureRemoveAll (_ context.Context , dir string ) error {
177- notExistErr := make (map [string ]bool )
178-
179- // track retries
180- exitOnErr := make (map [string ]int )
181- maxRetry := 50
182-
183- for {
184- err := os .RemoveAll (dir )
185- if err == nil {
186- return nil
187- }
188-
189- pe , ok := err .(* os.PathError )
190- if ! ok {
191- return err
192- }
193-
194- if os .IsNotExist (err ) {
195- if notExistErr [pe .Path ] {
196- return err
197- }
198- notExistErr [pe .Path ] = true
199-
200- // There is a race where some subdir can be removed but after the
201- // parent dir entries have been read.
202- // So the path could be from `os.Remove(subdir)`
203- // If the reported non-existent path is not the passed in `dir` we
204- // should just retry, but otherwise return with no error.
205- if pe .Path == dir {
206- return nil
207- }
208- continue
209- }
210-
211- if pe .Err != syscall .EBUSY {
212- return err
213- }
214-
215- if exitOnErr [pe .Path ] == maxRetry {
216- return err
217- }
218- exitOnErr [pe .Path ]++
219- time .Sleep (100 * time .Millisecond )
220- }
165+ return os .RemoveAll (dir )
221166}
222167
223168func modifyProcessLabel (runtimeType string , spec * specs.Spec ) error {
0 commit comments