Esempio n. 1
0
    def symlink(self, target, source):
        self.notReadOnly()

        created = False

        try:

            targetmatch = GremlinFSPath.match(target)
            sourcematch = GremlinFSPath.match(source)

            targetmatch.enter("symlink", target, source)
            if targetmatch and sourcematch:
                if not targetmatch.isFound():
                    created = targetmatch.createLink(sourcematch)
                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: symlink exception ', e)
            raise FuseOSError(errno.ENOENT)

        if created:
            return 0

        return 0
Esempio n. 2
0
    def write(self, path, data, offset, fh):
        self.notReadOnly()

        if not data:
            data = ""

        try:

            match = GremlinFSPath.match(path)
            match.enter("write", path, data, offset)
            if match:
                if match.isFile() and match.isFound():
                    data = match.writeFile(data, offset)
                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: write exception ', e)
            raise FuseOSError(errno.ENOENT)

        if data:
            return len(data)

        # raise FuseOSError(errno.ENOENT)
        return 0
Esempio n. 3
0
    def open(self, path, flags):

        found = False

        try:

            match = GremlinFSPath.match(path)
            match.enter("open", path, flags)
            if match:
                if match.isFile() and match.isFound():
                    found = True
                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: open exception ', e)
            raise FuseOSError(errno.ENOENT)

        if found:
            return 0

        return 0
Esempio n. 4
0
    def readlink(self, path):

        newpath = None

        try:

            match = GremlinFSPath.match(path)
            match.enter("readlink", path)
            if match:
                if match.isLink() and match.isFound():
                    newpath = match.readLink()
                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: readlink exception ', e)
            raise FuseOSError(errno.ENOENT)

        if newpath:
            return newpath

        return None
Esempio n. 5
0
    def read(self, path, size, offset, fh):

        data = None

        try:

            match = GremlinFSPath.match(path)
            match.enter("read", path, size, offset)
            if match:
                if match.isFile() and match.isFound():
                    data = match.readFile(size, offset)
                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: read exception ', )
            raise FuseOSError(errno.ENOENT)

        if data:
            return data

        return None
Esempio n. 6
0
    def mkdir(self, path, mode):
        self.notReadOnly()

        created = False

        try:

            match = GremlinFSPath.match(path)
            match.enter("mkdir", path, mode)

            if match:
                if not match.isFound():
                    created = match.createFolder()  # mode)

                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: mkdir exception ', e)
            raise FuseOSError(errno.ENOENT)

        if created:
            return 0

        return 0
Esempio n. 7
0
    def create(self, path, mode, fi=None):
        self.notReadOnly()

        created = False

        try:

            match = GremlinFSPath.match(path)
            match.enter("create", path, mode)
            if match:
                if not match.isFound():
                    created = match.createFile()  # mode)

                else:
                    # TODO: Wrong exception
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: create exception ', e)
            raise FuseOSError(errno.ENOENT)

        if created:
            return 0

        return 0
Esempio n. 8
0
    def rename(self, old, new):
        self.notReadOnly()

        renamed = False

        try:

            oldmatch = GremlinFSPath.match(old)
            newmatch = GremlinFSPath.match(new)
            oldmatch.enter("rename", old, new)
            if oldmatch and newmatch:

                # if oldmatch.isFile() and \
                #    oldmatch.isFound() and \
                #    not newmatch.isFound():
                #    renamed = oldmatch.renameFile(newmatch)
                # elif oldmatch.isFolder() and \
                #    oldmatch.isFound() and \
                #    not newmatch.isFound():
                #    renamed = oldmatch.renameFolder(newmatch)

                if oldmatch.isFile() and \
                   oldmatch.isFound():
                    if newmatch.isFound():
                        newmatch.deleteFile()
                    renamed = oldmatch.renameFile(newmatch)
                elif oldmatch.isFolder() and \
                   oldmatch.isFound():
                    if newmatch.isFound():
                        newmatch.deleteFolder()
                    renamed = oldmatch.renameFolder(newmatch)

                else:
                    raise FuseOSError(errno.ENOENT)

        # except FuseOSError:
        #     # Don't log here
        #     raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: rename exception ', )
            raise FuseOSError(errno.ENOENT)

        if renamed:
            return 0

        return 0
Esempio n. 9
0
    def rmdir(self, path):
        self.notReadOnly()

        try:

            match = GremlinFSPath.match(path)
            match.enter("rmdir", path)
            if match:
                if match.isFolder() and match.isFound():
                    match.deleteFolder()
                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: rmdir exception ', e)
            raise FuseOSError(errno.ENOENT)

        return 0
Esempio n. 10
0
    def chmod(self, path, mode):
        self.notReadOnly()
        try:

            match = GremlinFSPath.match(path)
            match.enter("chmod", path, mode)
            if match:
                if match.isFound():
                    match.setProperty("mode", mode)

                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: chmod exception ', e)
            raise FuseOSError(errno.ENOENT)

        return 0
Esempio n. 11
0
    def truncate(self, path, length, fh=None):
        self.notReadOnly()

        try:

            match = GremlinFSPath.match(path)
            match.enter("truncate", path)
            if match:
                if match.isFile() and match.isFound():
                    match.clearFile()
                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: truncate exception ', e)
            raise FuseOSError(errno.ENOENT)

        # raise FuseOSError(errno.ENOENT)
        return 0
Esempio n. 12
0
    def readdir(self, path, fh):

        entries = ['.', '..']

        try:

            match = GremlinFSPath.match(path)
            match.enter("readdir", path)
            if match:
                if match.isFolder() and match.isFound():
                    entries.extend(match.readFolder())
                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: readdir exception ', e)
            raise FuseOSError(errno.ENOENT)

        return entries
Esempio n. 13
0
    def unlink(self, path):
        self.notReadOnly()

        try:

            match = GremlinFSPath.match(path)
            match.enter("unlink", path)
            if match:
                if match.isFile() and match.isFound():
                    match.deleteFile()
                elif match.isLink() and match.isFound():
                    match.deleteLink()
                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: unlink exception ', e)
            raise FuseOSError(errno.ENOENT)

        return 0
Esempio n. 14
0
    def chown(self, path, uid, gid):
        self.notReadOnly()

        try:

            match = GremlinFSPath.match(path)
            match.enter("chown", path, uid, gid)
            if match:
                if match.isFound():
                    match.setProperty("owner", uid)
                    match.setProperty("group", gid)

                else:
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: chown exception ', e)
            raise FuseOSError(errno.ENOENT)

        return 0
Esempio n. 15
0
    def getattr(self, path, fh=None):

        now = time()
        owner = GremlinFSUtils.conf("default_uid", 0)  # 1001 # 0
        group = GremlinFSUtils.conf("default_gid", 0)  # 1001 # 0
        mode = GremlinFSUtils.conf("default_mode", 0o777)  # 0o777
        # data = None

        attrs = {
            "st_ino": 0,
            "st_mode": 0,
            "st_nlink": 0,
            "st_uid": owner,
            "st_gid": group,
            "st_size": 0,
            "st_atime": now,
            "st_mtime": now,
            "st_ctime": now,
        }

        try:

            match = GremlinFSPath.match(path)
            match.enter("getattr", path)
            if match:
                if match.isFolder() and match.isFound():
                    attrs.update({
                        "st_mode":
                        (stat.S_IFDIR | int(match.getProperty("mode", 0o777))),
                        "st_nlink":
                        int(match.getProperty("links", 1)),
                        "st_uid":
                        int(match.getProperty("owner", owner)),
                        "st_gid":
                        int(match.getProperty("group", group)),
                        "st_size":
                        1024,
                        # "st_atime": match.getProperty("", now),
                        # "st_mtime": match.getProperty("modified", now),
                        # "st_ctime": match.getProperty("created", now)
                    })

                elif match.isFile() and match.isFound():
                    match_file_length = 0
                    try:
                        # This one can throw errors via API as render returns
                        # 404 for empty file
                        match_file_length = match.readFileLength()
                    except Exception as e:
                        # Don't log here and don't throw exception, just set
                        # file length to 0
                        pass
                    attrs.update({
                        "st_mode":
                        (stat.S_IFREG | int(match.getProperty("mode", 0o777))),
                        "st_nlink":
                        int(match.getProperty("links", 1)),
                        "st_uid":
                        int(match.getProperty("owner", owner)),
                        "st_gid":
                        int(match.getProperty("group", group)),
                        "st_size":
                        match_file_length,  # match.readFileLength(),
                        # "st_atime": match.getProperty("", now),
                        # "st_mtime": match.getProperty("modified", now),
                        # "st_ctime": match.getProperty("created", now)
                    })

                elif match.isLink() and match.isFound():
                    attrs.update({
                        "st_mode":
                        (stat.S_IFLNK | int(match.getProperty("mode", 0o777))),
                        "st_nlink":
                        int(match.getProperty("links", 1)),
                        "st_uid":
                        int(match.getProperty("owner", owner)),
                        "st_gid":
                        int(match.getProperty("group", group)),
                        "st_size":
                        0,
                        # "st_atime": match.getProperty("", now),
                        # "st_mtime": match.getProperty("modified", now),
                        # "st_ctime": match.getProperty("created", now)
                    })

                else:
                    # Note; Unless I throw this here, I am unable to
                    # touch files as attributes. I think the default
                    # here should be to throw FuseOSError(errno.ENOENT)
                    # unless file/node is actually found
                    raise FuseOSError(errno.ENOENT)

        except FuseOSError:
            # Don't log here
            raise FuseOSError(errno.ENOENT)

        except Exception as e:
            self.logger.exception(' GremlinFS: getattr exception ', e)
            raise FuseOSError(errno.ENOENT)

        return attrs