Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: fix Pebble.DeleteDirAndFiles #48144

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions pkg/storage/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,31 +970,14 @@ func (p *Pebble) DeleteFile(filename string) error {

// DeleteDirAndFiles implements the Engine interface.
func (p *Pebble) DeleteDirAndFiles(dir string) error {
// TODO(itsbilal): Implement FS.RemoveAll then call that here instead.
files, err := p.fs.List(dir)
// NB RemoveAll does not return an error if dir does not exist, but we want
// DeleteDirAndFiles to return an error in that case to match the RocksDB
// behavior.
_, err := p.fs.Stat(dir)
if err != nil {
return err
}

// Recurse through all files, calling DeleteFile or DeleteDirAndFiles as
// appropriate.
for _, filename := range files {
path := p.fs.PathJoin(dir, filename)
stat, err := p.fs.Stat(path)
if err != nil {
return err
}

if stat.IsDir() {
err = p.DeleteDirAndFiles(path)
} else {
err = p.DeleteFile(path)
}
if err != nil {
return err
}
}
return nil
return p.fs.RemoveAll(dir)
}

// LinkFile implements the FS interface.
Expand Down