Eds*_*ina 6 file-permissions go
我正在尝试使用 ioutils.WriteFile() 但由于某种原因它忽略了我授予它的 0777 权限。
package main
import (
"io/ioutil"
"os"
)
func main() {
// normal permissions
if err := ioutil.WriteFile("cant-touch-this-0644", []byte{}, 0644); err != nil {
panic(err)
}
// full permissions
if err := ioutil.WriteFile("cant-touch-this-0777", []byte{}, 0777); err != nil {
panic(err)
}
// normal permissions + chmod to full
if err := ioutil.WriteFile("cant-touch-this-mixed", []byte{}, 0755); err != nil {
panic(err)
}
if err := os.Chmod("cant-touch-this-mixed", 0777); err != nil {
panic(err)
}
}
Run Code Online (Sandbox Code Playgroud)
我从中得到的输出是:
$ ls -l
-rw-r--r-- 1 edson edson 0 May 9 17:19 cant-touch-this-0644
-rwxr-xr-x 1 edson edson 0 May 9 17:19 cant-touch-this-0777
-rwxrwxrwx 1 edson edson 0 May 9 17:19 cant-touch-this-mixed
Run Code Online (Sandbox Code Playgroud)
意思是:
os.Chmod(如第三种情况)我究竟做错了什么?