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

os: RemoveAll no longer able to remove empty directory without read permission #29178

dmitshur opened this issue Dec 11, 2018 · 2 comments


Copy link

@dmitshur dmitshur commented Dec 11, 2018

There is a change in behavior of os.RemoveAll on tip compared to 1.11.2, on macOS (and Linux, BSDs), caused by CL 146020, in a specific scenario. I can't definitively say whether this change should considered a bug/regression, or if it's a normal intentional new behavior, so marking as NeedsDecision.

Prior to CL 146020, it was possible to use os.RemoveAll to remove an empty directory without read permissions, because its code had a "Simple case" as the first thing it tried:

func RemoveAll(path string) error {
	// Simple case: if Remove works, we're done.
	err := Remove(path)
	if err == nil || IsNotExist(err) {
		return nil


So the Go program printed temp file was removed: true.

The new os.RemoveAll code after CL 146020 tries to read the directory before performing the "simple case", and returns a permission error instead:

$ go run .
temp file was removed: true
$ gotip run .
2018/12/11 16:14:39 os.RemoveAll: permission denied
exit status 1

/cc @ostenbom @ianlancetaylor

@dmitshur dmitshur added this to the Go1.12 milestone Dec 11, 2018

This comment has been minimized.

Copy link

@bradfitz bradfitz commented Dec 11, 2018

I think this is worth fixing for Go 1.12.


This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 12, 2018

Change mentions this issue: os: in RemoveAll, try Remove first

@gopherbot gopherbot closed this in ba1de79 Dec 12, 2018
@dmitshur dmitshur added NeedsFix and removed NeedsDecision labels Dec 12, 2018
@golang golang locked and limited conversation to collaborators Dec 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.