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

macOS: Unsorted scan is incompatible with removing files from the directory #57

Open
dottedmag opened this issue Sep 3, 2020 · 0 comments
Assignees

Comments

@dottedmag
Copy link

The following code for recursive directory removal used to work until 74f3b4a. Since that change it started to skip files under macOS (probably filesystem-specific and might be triggered under Linux too) and failing in PostChildrenCallback with ENOTEMPTY.

I am not sure this is expected behaviour, so either fixing or documenting it would be useful.

func RemoveIfExists(f string) error {
	if err := os.Remove(f); err != nil && !os.IsNotExist(err) {
		return err
	}
	return nil
}

func Rmr(dir string) error {
	err := godirwalk.Walk(dir, &godirwalk.Options{
		Callback: func(path string, de *godirwalk.Dirent) error {
			if de.IsDir() {
				// Directory itself will be removed in PostChildrenCallback
				return nil
			}
			return RemoveIfExists(path)
		},
		PostChildrenCallback: func(path string, de *godirwalk.Dirent) error {
			return RemoveIfExists(path)
		},
		Unsorted: true,
	})
	if os.IsNotExist(err) {
		return nil
	}
	return err
}
@karrick karrick self-assigned this Sep 4, 2020
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

No branches or pull requests

2 participants