Skip to content

Commit

Permalink
Update withNestedDir to remove everything (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Sep 25, 2024
1 parent db97e7e commit f4c9883
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion io/local/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ func (w *Writer) RemoveFiles(ctx context.Context) error {

return nil
}

if w.withNestedDir {
if err = os.RemoveAll(w.path); err != nil {
return fmt.Errorf("failed to remove path %s: %w", w.path, err)
}

return nil
}

// If it is a dir.
files, err := os.ReadDir(w.path)
if err != nil {
Expand All @@ -147,7 +156,7 @@ func (w *Writer) RemoveFiles(ctx context.Context) error {
for _, file := range files {
filePath := filepath.Join(w.path, file.Name())
// Skip folders.
if file.IsDir() && !w.withNestedDir {
if file.IsDir() {
continue
}
// If validator is set, remove only valid files.
Expand Down

0 comments on commit f4c9883

Please sign in to comment.