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: MkdirAll fails if permissions do not include execute for owner #22323

Closed
zwass opened this issue Oct 18, 2017 · 2 comments
Closed

os: MkdirAll fails if permissions do not include execute for owner #22323

zwass opened this issue Oct 18, 2017 · 2 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@zwass
Copy link

zwass commented Oct 18, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/zwass/dev/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4k/2q3ctn7d5_xb03_zsb3v6lgr0000gn/T/go-build972837205=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Println(os.MkdirAll("foo/bar", 0644))
}

What did you expect to see?

No error. Directories are created with the provided permission bits (modified by umask).

Or, following the rules as described for mkdir -p:

Intermediate directories are created with permission bits of rwxrwxrwx (0777) as modified by the current umask, plus write and search permission for the owner.

What did you see instead?

mkdir foo/bar: permission denied

The directory foo is created (with perms as expected after including umask), but the directory foo/bar is not.

@ianlancetaylor ianlancetaylor changed the title os.MkdirAll fails if permissions do not include execute for owner os: MkdirAll fails if permissions do not include execute for owner Oct 18, 2017
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 18, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Oct 18, 2017
@robpike
Copy link
Contributor

robpike commented Oct 18, 2017

It's doing exactly what the documentation says it does. I don't believe this is a bug. A change like this is a feature request but I'm not sure it should be done as it is considerably more complex and racy to do what is asked than to do what is specified.

@ianlancetaylor ianlancetaylor added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. and removed NeedsFix The path to resolution is known, but the work has not been done. labels Oct 19, 2017
@rsc
Copy link
Contributor

rsc commented Oct 30, 2017

mkdir(1) documents that the -m mode applies only to the final created directory, while os.MkdirAll documents that the permission bits apply to all directories. I don't believe we can change either one to bring them in line with each other at this point. It's unfortunate, but easy to work around: allow at least the 0700 bits, or use an os.MkdirAll for the parent followed by an os.Mkdir with mode 0 for the final element.

@rsc rsc closed this as completed Oct 30, 2017
@golang golang locked and limited conversation to collaborators Oct 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants