Skip to content

Conversation

@erinpentecost
Copy link
Contributor

No description provided.

@erinpentecost erinpentecost self-assigned this Jul 16, 2021
@erinpentecost
Copy link
Contributor Author

I should put in a check to not delete parents of the toplevel cloud store folder.

localfs/store.go Outdated

for dirName := path.Dir(filePath); len(dirName) > 0; dirName = path.Dir(dirName) {
dir, err := os.Open(dirName)
if os.IsNotExist(err) {
Copy link
Member

Choose a reason for hiding this comment

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

This block has race conditions between checking existence and emptiness, which is unnecessary as os.Remove() errors on non-empty dirs.

Just try to os.Remove() every parent dir, ignoring the dir already not existing or not being empty (ceasing looping if you hit a non-empty error)

Comment on lines 12 to 14
testDir, err := os.MkdirTemp("/tmp", "dirtest")
require.NoError(t, err)
defer os.RemoveAll(testDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

[NIT] t.TempDir() does all this for us IIRC:

Suggested change
testDir, err := os.MkdirTemp("/tmp", "dirtest")
require.NoError(t, err)
defer os.RemoveAll(testDir)
testDir := t.TempDir()

err := os.MkdirAll(dir, 0755)
require.NoError(t, err)
err = os.WriteFile(fullPath, []byte("don't delete this folder"), 0755)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're using subtests below I believe you need to accept t testing.TB as an argument, otherwise you'll reference the wrong *testing.T.

localfs/store.go Outdated
Comment on lines 314 to 315
if pathErr, ok := err.(*fs.PathError); ok {
if sysErr, ok := pathErr.Err.(syscall.Errno); ok && sysErr == syscall.ENOTEMPTY {
Copy link
Contributor

Choose a reason for hiding this comment

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

[NIT] errors.As() is preferred here AFAIK: https://pkg.go.dev/errors

@erinpentecost erinpentecost merged commit 1c8a12f into master Jul 19, 2021
@erinpentecost erinpentecost deleted the localfs_delete branch July 19, 2021 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants