-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfs_remove_all.go
More file actions
39 lines (33 loc) · 797 Bytes
/
Copy pathfs_remove_all.go
File metadata and controls
39 lines (33 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package command
import (
"context"
"errors"
"lesiw.io/fs"
)
var _ fs.RemoveAllFS = (*cmdFS)(nil)
func (cfs *cmdFS) RemoveAll(ctx context.Context, name string) (err error) {
if err = cfs.init(ctx); err != nil {
return
}
switch cfs.kind {
case kindGNU, kindBSD:
err = Do(ctx, cfs, "rm", "-rf", name)
case kindWindows:
err = psDo(ctx, cfs,
"Remove-Item -Path '%s' -Recurse -Force "+
"-ErrorAction SilentlyContinue",
name,
)
if e := new(Error); errors.As(err, &e) && e.Code == 1 {
err = nil // Ignore "path not found" errors.
}
case kindDOS:
err = Do(ctx, cfs, "cmd", "/c", "rmdir", "/S", "/Q", name)
if e := new(Error); errors.As(err, &e) && e.Code == 2 {
err = nil // Ignore "path not found" errors.
}
default:
err = errUnsupportedOS
}
return
}