Skip to content

Commit 81c1436

Browse files
committed
Add remove for filemanager
1 parent 38cdffc commit 81c1436

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

service/filemanager/default.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ func (m *defaultManager) MkdirAll(path string, perm os.FileMode) error {
154154
return nil
155155
}
156156

157+
func (m *defaultManager) Remove(path string) error {
158+
path = m.BasePath(path)
159+
return os.Remove(path)
160+
}
161+
162+
func (m *defaultManager) RemoveAll(path string) error {
163+
path = m.BasePath(path)
164+
return os.RemoveAll(path)
165+
}
166+
157167
func fixRootDirectory(p string) string {
158168
if len(p) == len(`\\?\c:`) {
159169
if os.IsPathSeparator(p[0]) && os.IsPathSeparator(p[1]) && p[2] == '?' && os.IsPathSeparator(p[3]) && p[5] == ':' {

service/filemanager/manager.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ type Manager interface {
1414
CreateTemp(pattern string) (*os.File, error)
1515
Mkdir(path string, perm os.FileMode) error
1616
MkdirAll(path string, perm os.FileMode) error
17+
Remove(path string) error
18+
RemoveAll(path string) error
1719
}
1820

1921
func BasePath(ctx context.Context, name string) string {
@@ -64,6 +66,22 @@ func MkdirAll(ctx context.Context, path string, perm os.FileMode) error {
6466
return manager.MkdirAll(path, perm)
6567
}
6668

69+
func Remove(ctx context.Context, path string) error {
70+
manager := service.FromContext[Manager](ctx)
71+
if manager == nil {
72+
return os.Remove(path)
73+
}
74+
return manager.Remove(path)
75+
}
76+
77+
func RemoveAll(ctx context.Context, path string) error {
78+
manager := service.FromContext[Manager](ctx)
79+
if manager == nil {
80+
return os.RemoveAll(path)
81+
}
82+
return manager.RemoveAll(path)
83+
}
84+
6785
func WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error {
6886
manager := service.FromContext[Manager](ctx)
6987
if manager == nil {

0 commit comments

Comments
 (0)