FListMetadata.py 文件源码

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

项目:lib9 作者: Jumpscale 项目源码 文件源码
def chmod(self, ppath, mode):
        """
        Change mode for files or directories
        :param ppath: path of file/dir
        :param mode: string of the mode

        Examples:
        flistmeta.chmod("/tmp/dir1", "777")
        """
        fType, dirObj = self._search_db(ppath)
        if dirObj.dbobj.state != "":
            raise RuntimeError("%s: No such file or directory" % ppath)

        try:
            mode = int(mode, 8)
        except ValueError:
            raise ValueError("Invalid mode.")
        else:
            if fType == "D":
                _mode = mode + stat.S_IFDIR
                aclObj = self.aciCollection.get(dirObj.dbobj.aclkey)
                aclObj.dbobj.mode = _mode
                aclObj.save()

            elif fType == "F" or fType == "L":
                _mode = mode + stat.S_IFREG if fType == "F" else mode + stat.S_IFLNK
                _, propList = self._getPropertyList(dirObj.dbobj, fType)
                for file in propList:
                    if file.name == j.sal.fs.getBaseName(ppath):
                        aclObj = self.aciCollection.get(file.aclkey)
                        aclObj.dbobj.mode = _mode
                        aclObj.save()
            else:
                for file in dirObj.dbobj.links:
                    if file.name == j.sal.fs.getBaseName(ppath):
                        aclObj = self.aciCollection.get(file.aclkey)
                        if stat.S_ISSOCK(aclObj.dbobj.st_mode):
                            _mode = mode + stat.S_IFSOCK
                        elif stat.S_ISBLK(aclObj.dbobj.st_mode):
                            _mode = mode + stat.S_IFBLK
                        elif stat.S_ISCHR(aclObj.dbobj.st_mode):
                            _mode = mode + stat.S_IFCHR
                        elif stat.S_ISFIFO(aclObj.dbobj.st_mode):
                            _mode = mode + stat.S_IFIFO
                        aclObj.dbobj.mode = _mode
                        aclObj.save()
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号