os.MkDir and os.MkDirAll permission value?

后端 未结 5 1009
余生分开走
余生分开走 2020-12-02 07:27

I\'m trying to create a log file at the start of my program.

I need to check if a \"/log\" directory exists if it doesn\'t create the directory then move on to creat

5条回答
  •  再見小時候
    2020-12-02 07:48

    You can reset the umask to 0. I would call this as the first thing in my main file

    syscall.Umask(0)
    

    Example

    _ = os.MkdirAll("/tmp/dirs/1", 0664)
    syscall.Umask(0)
    _ = os.MkdirAll("/tmp/dirs/2", 0664)
    

    Result

    /tmp/dirs$ stat -c '%A %a %n' *
    drw-r--r-- 644 1
    drw-rw-r-- 664 2
    

提交回复
热议问题