server.py 文件源码

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

项目:borgcube 作者: enkore 项目源码 文件源码
def check(self):
        """Verify correct permissions and ownership of database files."""
        scheme, _, file, _, _ = urlsplit(settings.DB_URI)
        if scheme != 'file':
            log.warning('DB_URI does not point to a file but %s -- forgot to set "BUILTIN_ZEO = False"?', scheme)
            return

        try:
            st = os.stat(file)
        except FileNotFoundError:
            # Database not created yet, not an error.
            return

        error = False
        if st.st_uid != os.geteuid():
            log.error('Database file %s has wrong owner: %d (file) vs %d (daemon user)', file, st.st_uid, os.geteuid())
            error = True
        if st.st_gid != os.getegid():
            log.error('Database file %s has wrong group: %d (file) vs %d (daemon user)', file, st.st_gid, os.getegid())
            # not a critical error, could be, theoretically, on purpose
        if error:
            sys.exit(1)

        # Fix perms, if any
        perms = stat.S_IMODE(st.st_mode)
        perms_should_be = perms & ~stat.S_IRWXO
        if perms != perms_should_be:
            try:
                os.chmod(file, perms_should_be)
            except OSError as ose:
                log.debug('Tried to fix permissions on database file, but it didn\'t work: %s', file, ose)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号