path.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:scarlett_os 作者: bossjones 项目源码 文件源码
def enforce_file_permissions(path):
    # source: dcos-cli
    """Enforce 400 or 600 permissions on file

    :param path: Path to the TOML file
    :type path: str
    :rtype: None
    """

    if not os.path.isfile(path):
        raise Exception('Path [{}] is not a file'.format(path))

    permissions = oct(stat.S_IMODE(os.stat(path).st_mode))
    if permissions not in ['0o600', '0600', '0o400', '0400']:
        if os.path.realpath(path) != path:
            path = '%s (pointed to by %s)' % (os.path.realpath(path), path)
        msg = (
            "Permissions '{}' for configuration file '{}' are too open. "
            "File must only be accessible by owner. "
            "Aborting...".format(permissions, path))
        raise Exception(msg)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号