Skip to content

Commit

Permalink
Merge pull request #72 from twpayne/cleanup-perms
Browse files Browse the repository at this point in the history
Handle some permission errors in test cleanup
  • Loading branch information
twpayne authored Mar 31, 2024
2 parents 4018512 + 563828b commit 906833b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion vfst/testfs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package vfst

import (
"errors"
"io/fs"
"os"

vfs "github.com/twpayne/go-vfs/v5"
Expand Down Expand Up @@ -54,6 +56,23 @@ func (t *TestFS) TempDir() string {

func (t *TestFS) cleanup() {
if !t.keep {
os.RemoveAll(t.tempDir)
for {
// Remove t.tempDir but try to recover from permission denied errors
// by chmod'ing the path that causes the error.
err := os.RemoveAll(t.tempDir)
if err == nil {
break
}
if !errors.Is(err, fs.ErrPermission) {
break
}
var pathErr *os.PathError
if !errors.As(err, &pathErr) {
break
}
if err := os.Chmod(pathErr.Path, 0o777); err != nil {
break
}
}
}
}

2 comments on commit 906833b

@Lorik56
Copy link

@Lorik56 Lorik56 commented on 906833b Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lorik56
Copy link

@Lorik56 Lorik56 commented on 906833b Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.