Ejemplo n.º 1
0
 def stat(self):
     statobj = Stat(st_ino = self.id, st_uid = os.getuid(), st_gid = os.getgid(), st_size = self.size, st_atime = self.atime, st_mtime = self.mtime, st_ctime = self.ctime, st_nlink = 0)
     if self.kind == FSNODE_FOLDER:
         statobj.st_mode = STAT_UMASK | stat.S_IFDIR
     else:
         statobj.st_mode = STAT_UMASK | stat.S_IFLNK
     return statobj
Ejemplo n.º 2
0
 def wrapper(self, path):
     if path in INFO_CACHE:
         st = INFO_CACHE[path]
         f = Stat()
         f.st_nlink = 1
         f.st_mode = st[0]
         f.st_size = st[1]
         return f
     else:
         f = fn(self, path)
         if isinstance(f, Stat):
             INFO_CACHE[path] = (f.st_mode, f.st_size)
         return f
Ejemplo n.º 3
0
 def stat(self):
     statobj = Stat(st_ino=self.id,
                    st_uid=os.getuid(),
                    st_gid=os.getgid(),
                    st_size=self.size,
                    st_atime=self.atime,
                    st_mtime=self.mtime,
                    st_ctime=self.ctime,
                    st_nlink=0)
     if self.kind == FSNODE_FOLDER:
         statobj.st_mode = STAT_UMASK | stat.S_IFDIR
     else:
         statobj.st_mode = STAT_UMASK | stat.S_IFLNK
     return statobj
Ejemplo n.º 4
0
    def getattr(self, path):
        """Read file attributes"""

        log.debug('get attr: %s' % path)

        # TODO: remove internal use of __getinode
        # - use __inode_cache operations instead

        inode = self.__getinode(path)
        if inode:
            if log.isEnabledFor(logging.DEBUG):
                log.debug('inode %s' % inode)
            blocks = inode['size'] / default_block_size + (
                inode['size'] % default_block_size != 0)
            stat_dict = {
                'st_blksize': default_block_size,
                'st_rdev': inode['dev'],
                'st_blocks': blocks,
                'st_mode': inode['mode'],
                'st_ino': inode['ino'],
                'st_dev': inode['dev'],
                'st_nlink': inode['nlink'],
                'st_uid': inode['uid'],
                'st_gid': inode['gid'],
                'st_size': inode['size'],
                'st_atime': inode['atime'],
                'st_mtime': inode['mtime'],
                'st_ctime': inode['ctime'],
            }
            if log.isEnabledFor(logging.DEBUG):
                log.debug('stat_dict: %s' % stat_dict)
            stats = Stat(**stat_dict)
            return stats
        else:
            err = OSError('No such file: %s' % path)
            err.errno = ENOENT
            raise err
Ejemplo n.º 5
0
 def getattr(self):
     st = Stat()
     return st
Ejemplo n.º 6
0
 def getattr(self):
     st = Stat()
     st.st_size = self.inode.file_size
     st.st_mode = stat.S_IFREG | 0666
     return st
Ejemplo n.º 7
0
 def pre_getattr(self, path):
     st = Stat()
     pe = getParts(path)
     st.st_mode = stat.S_IFDIR | 0555
     st.st_ino = 0
     st.st_dev = 0
     st.st_nlink = 2
     st.st_uid = 0
     st.st_gid = 0
     st.st_size = 4096
     st.st_atime = 0
     st.st_mtime = 0
     st.st_ctime = 0
     if self.is_root(pathelts=pe):
         return st
     if len(pe) < 3:  # ext dir
         query = "SELECT COUNT(*) FROM files WHERE newname like '{0}%';".format(
             escape_for_sql(pe[-1]))
         try:
             self.DBG(query)
             self.cursor.execute(query)
             cnt = self.cursor.fetchone()
         except Exception as e:
             self.DBG("Whoa, except: {0}".format(str(e)))
             cnt = [0]
         if cnt[0] < 1:
             self.DBG("Nothing returned, ENOENT")
             return -fuse.ENOENT
         return st
     else:
         st.st_mode = stat.S_IFLNK | 0777
         st.st_nlink = 1
         st.st_size = 0
         newname = self.namekey(pe[-1])
         # I guess I should search on the name and not _id, so that
         # using dummy names with real _ids won't work.
         query = "SELECT COUNT(*) FROM files WHERE newname='{0}';".format(
             escape_for_sql(newname))
         try:
             self.DBG(query)
             self.cursor.execute(query)
             cnt = self.cursor.fetchone()
         except Exception as e:
             self.DBG("Whoa, except: {0}".format(e))
             cnt = [0]
         if cnt[0] < 1:
             self.DBG("File not found.")
             return -fuse.ENOENT
     return st
Ejemplo n.º 8
0
Archivo: file.py Proyecto: chiiph/ESFS
 def getattr(self):
     st = Stat()
     st.st_size = self.inode.file_size
     st.st_mode = stat.S_IFREG | 0666
     return st
Ejemplo n.º 9
0
    def getattr(self, path):
        st = Stat()
        st.st_nlink = 1
        if self._sh('test -e "%s"&&echo true' % path).strip() != 'true':
            return -ENOENT

        elif self._sh('test -h "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFLNK

        elif self._sh('test -d "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFDIR

        elif self._sh('test -f "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFREG

        elif self._sh('test -c "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFCHR

        elif self._sh('test -b "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFBLK

        elif self._sh('test -p "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFIFO

        elif self._sh('test -s "%s"&&echo true' % path).strip() == 'true':
            st.st_mode = stat.S_IFSOCK

        else:
            st.st_mode = 0

        st.st_mode |= int(self._sh('stat -c%%a "%s"' % path) or '0', 8)
        st.st_size = int(self._sh('stat -c%%s "%s"' % path) or '0')
        print "file:", path, "size: ", st.st_size, "mode:", oct(st.st_mode)

        return st