diff options
| author | Michael Tews <michael@tews.dev> | 2026-03-31 06:12:15 +0200 |
|---|---|---|
| committer | Michael Tews <michael@tews.dev> | 2026-03-31 06:12:15 +0200 |
| commit | 21beb6a683652e4e8b72318826fcec19c5418b48 (patch) | |
| tree | c39eaf0e8f4a494b819934f4e3666c181cee8b28 | |
| parent | 752c8e80d528cb17fbe129ade4234e571a36354d (diff) | |
feat: add Purge
| -rw-r--r-- | backend/studip/fs.go | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/backend/studip/fs.go b/backend/studip/fs.go index df18171..32ed19a 100644 --- a/backend/studip/fs.go +++ b/backend/studip/fs.go @@ -1339,7 +1339,7 @@ func (f *Fs) updateRelativeRootFromTree() { fs.Debugf(f, "resolved relative root path=%q id=%q", rootNode.Path, rootNode.ID) } -func (f *Fs) Rmdir(ctx context.Context, dir string) error { +func (f *Fs) rmdir(ctx context.Context, dir string, purge bool) error { if ctx.Err() != nil { return ctx.Err() } @@ -1393,18 +1393,21 @@ func (f *Fs) Rmdir(ctx context.Context, dir string) error { if err != nil { return err } - if len(node.Children) > 0 { - if refreshErr := f.refreshFileTree(ctx); refreshErr != nil { - fs.Debugf(f, "Rmdir: refresh before empty check failed dir=%q err=%v", dir, refreshErr) - } else { - node, err = lookupNode() - if err != nil { - return err - } - } + if !purge { if len(node.Children) > 0 { - return fs.ErrorDirectoryNotEmpty + if refreshErr := f.refreshFileTree(ctx); refreshErr != nil { + fs.Debugf(f, "Rmdir: refresh before empty check failed dir=%q err=%v", dir, refreshErr) + } else { + node, err = lookupNode() + if err != nil { + return err + } + } + + if len(node.Children) > 0 { + return fs.ErrorDirectoryNotEmpty + } } } @@ -1431,6 +1434,10 @@ func (f *Fs) Rmdir(ctx context.Context, dir string) error { return nil } +func (f *Fs) Rmdir(ctx context.Context, dir string) error { + return f.rmdir(ctx, dir, false) +} + func (f *Fs) TestConnection( ctx context.Context, ) error { @@ -1471,12 +1478,16 @@ func (f *Fs) Features() *fs.Features { return (&fs.Features{ CanHaveEmptyDirectories: true, CaseInsensitive: true, - Copy: nil, - Purge: nil, + // TODO: Implement this + Copy: nil, }). Fill(context.Background(), f) } +func (f *Fs) Purge(ctx context.Context, dir string) error { + return f.rmdir(ctx, dir, true) +} + func (f *Fs) Move( ctx context.Context, src fs.Object, |
