douhui9192 2015-04-27 11:50
浏览 655
已采纳

使用os.Mkdir()创建的文件夹具有不正确的权限

I am creating a folder in go using os.Mkdir(). While it does get created, it does not possess the permissions I expected it to.

Here is the code I used to create the directory:

package main

import (
    "fmt"
    "os"
)

func main() {
    err := os.Mkdir("/var/run/testdir", 0777)
    if err != nil {
        fmt.Println("could not create dir: %s", err.Error())
        err = nil
    }
}

As I have given "0777" as parameter, I am excpecting the created dir to have full permissions for everybody. It however has:

drwxr-xr-x  2 root       root         40 Apr 27 11:43 testdir/

What am I getting wrong here?

  • 写回答

1条回答 默认 最新

  • doutizhou5312 2015-04-27 12:07
    关注

    The actual permission that the created folder will get is the result of the permission you specify (0777) and the active umask of your process (the running Go program).

    This is most likely why the created folder lacks write permission for group and other access.

    You can read more about umask on Wikipedia.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度