-
Notifications
You must be signed in to change notification settings - Fork 17.3k
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.Mkdir and os.MkdirAll set wrong permission bits #15210
Comments
@sn-amber it seems umask is being applied when creating the file. It filter the permissions when creating a file. You can check the umask value by running umask in a terminal and also change it before running your program to verify, e.g. calling |
You can also set the umask for the process using |
Closing, because umask is a standard Unix feature that affects programs in all languages. |
What would you think about adding this information to documentation? That permissions might be affected by Umask and that you can set it with syscall.Umask? |
I don't think the Go documentation is the place to discuss details of how the Unix operating system works. If we go down that path we'll wind up documenting things like how the setgid bit of the directory affects file ownership, and the relationship between the effective user ID and file ownership, and I just don't think we should go there. There are many text books and web pages that explain how Unix works. That said, I could imagine documenting some of these characteristics in a Unix-specific section of the package docs, if somebody wants to work on that. I don't know what others would think of that, though. |
I should add that this is a discussion to have on the golang-dev mailing list, not on this closed issue. |
Please answer these questions before submitting your issue. Thanks!
go version
)?go version go1.6 linux/amd64
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/golang"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
I created a directory using
os.Mkdir("foo", 0007)
and got a folder with permissions------r-x
instead of------rwx
.This behavior could not be repeated on play.golang.org.
However this program can be used to recreate similar behavior:
I expected the folders
foo
andbar
to both have permissions------rwx
Folder
foo
was created with permissions------r-x
.os.Chmod
was setting the permissions correctly, sobar
ends up with permissions------rwx
This is the output of the program above:
The text was updated successfully, but these errors were encountered: