diff --git a/service/filemanager/default.go b/service/filemanager/default.go index 96e7c4c..f7b984e 100644 --- a/service/filemanager/default.go +++ b/service/filemanager/default.go @@ -154,6 +154,16 @@ func (m *defaultManager) MkdirAll(path string, perm os.FileMode) error { return nil } +func (m *defaultManager) Remove(path string) error { + path = m.BasePath(path) + return os.Remove(path) +} + +func (m *defaultManager) RemoveAll(path string) error { + path = m.BasePath(path) + return os.RemoveAll(path) +} + func fixRootDirectory(p string) string { if len(p) == len(`\\?\c:`) { if os.IsPathSeparator(p[0]) && os.IsPathSeparator(p[1]) && p[2] == '?' && os.IsPathSeparator(p[3]) && p[5] == ':' { diff --git a/service/filemanager/manager.go b/service/filemanager/manager.go index f4af5b9..6367146 100644 --- a/service/filemanager/manager.go +++ b/service/filemanager/manager.go @@ -14,6 +14,8 @@ type Manager interface { CreateTemp(pattern string) (*os.File, error) Mkdir(path string, perm os.FileMode) error MkdirAll(path string, perm os.FileMode) error + Remove(path string) error + RemoveAll(path string) error } func BasePath(ctx context.Context, name string) string { @@ -64,6 +66,22 @@ func MkdirAll(ctx context.Context, path string, perm os.FileMode) error { return manager.MkdirAll(path, perm) } +func Remove(ctx context.Context, path string) error { + manager := service.FromContext[Manager](ctx) + if manager == nil { + return os.Remove(path) + } + return manager.Remove(path) +} + +func RemoveAll(ctx context.Context, path string) error { + manager := service.FromContext[Manager](ctx) + if manager == nil { + return os.RemoveAll(path) + } + return manager.RemoveAll(path) +} + func WriteFile(ctx context.Context, name string, data []byte, perm os.FileMode) error { manager := service.FromContext[Manager](ctx) if manager == nil {