$ ll /tmp total 160K drwxr-xr-x 3 root root 4.0K Dec 15 2020 apollo -rw-r--r-- 1 user user 0 Dec 17 15:30 file drwx------ 2 root root 4.0K Sep 18 2020 go-build080350710 drwxr-xr-x 2 user user 4.0K Dec 17 15:25 prem ...
原因
方法注释中都已经写明白了,重点都是(before umask),看源码 Linux umask命令指定在建立文件时预设的权限掩码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// src/os/file.go // Create creates or truncates the named file. If the file already exists, // it is truncated. If the file does not exist, it is created with mode 0666 // (before umask). If successful, methods on the returned File can // be used for I/O; the associated file descriptor has mode O_RDWR. // If there is an error, it will be of type *PathError. funcCreate(name string) (*File, error) { return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666) }
// src/os/path.go // MkdirAll creates a directory named path, // along with any necessary parents, and returns nil, // or else returns an error. // The permission bits perm (before umask) are used for all // directories that MkdirAll creates. // If path is already a directory, MkdirAll does nothing // and returns nil. funcMkdirAll(path string, perm FileMode)error {...}