package main
import (
"fmt"
"io/ioutil"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
ioutil.WriteFile("test.txt", []byte("Hello world"), 0222)
b, e := ioutil.ReadFile("test.txt")
check(e)
fmt.Println(string(b))
}
I'm using the io/ioutil
package to read/write a file, and setting the permissions to 0222 (write, write, write) when writing the file still allows me to read the file after it's written.
Using stat test.txt
in Bash, the access shows as (0644/-rw-r--r--)
.
Why is the file written with 0644 permissions and not the specified 0222?