Exemplo n.º 1
0
    def stat(self, path):
        try:
            st = os.stat(path, follow_symlinks=False)
            a = acl.ACL(file=path)
        except OSError as err:
            raise RpcException(err.errno, str(err))

        try:
            user = self.dispatcher.call_sync('dscached.account.getpwuid',
                                             st.st_uid)
            domain = q.get(user, 'origin.domain')
            at = '@' if domain else None
            username = f'{user["username"]}{at}{domain}'
        except RpcException:
            username = None

        try:
            group = self.dispatcher.call_sync('dscached.group.getgrgid',
                                              st.st_gid)
            domain = q.get(group, 'origin.domain')
            at = '@' if domain else None
            groupname = f'{group["name"]}{at}{domain}'
        except RpcException:
            groupname = None

        return {
            'path': path,
            'type': get_type(st),
            'atime': datetime.utcfromtimestamp(st.st_atime),
            'mtime': datetime.utcfromtimestamp(st.st_mtime),
            'ctime': datetime.utcfromtimestamp(st.st_ctime),
            'uid': st.st_uid,
            'user': username,
            'gid': st.st_gid,
            'group': groupname,
            'permissions': {
                'acl': self.dispatcher.threaded(a.__getstate__),
                'user': username,
                'group': groupname,
                'modes': {
                    'value': st.st_mode & 0o777,
                    'user': {
                        'read': bool(st.st_mode & stat.S_IRUSR),
                        'write': bool(st.st_mode & stat.S_IWUSR),
                        'execute': bool(st.st_mode & stat.S_IXUSR)
                    },
                    'group': {
                        'read': bool(st.st_mode & stat.S_IRGRP),
                        'write': bool(st.st_mode & stat.S_IWGRP),
                        'execute': bool(st.st_mode & stat.S_IXGRP)
                    },
                    'others': {
                        'read': bool(st.st_mode & stat.S_IROTH),
                        'write': bool(st.st_mode & stat.S_IWOTH),
                        'execute': bool(st.st_mode & stat.S_IXOTH)
                    },
                }
            }
        }
Exemplo n.º 2
0
 def listdir(self, directory):
     for i in sorted(os.listdir(directory)):
         path = os.path.join(directory, i)
         stat = os.lstat(path)
         yield {
             'type': get_type(stat),
             'size': stat.st_size,
             'created_at': datetime.utcfromtimestamp(stat.st_ctime),
             'modified_at': datetime.utcfromtimestamp(stat.st_mtime),
             'name': i,
             'path': path
         }
Exemplo n.º 3
0
    def stat(self, path):
        try:
            st = os.stat(path, follow_symlinks=False)
            a = acl.ACL(file=path)
        except OSError as err:
            raise RpcException(err.errno, str(err))

        try:
            username = self.dispatcher.threaded(pwd.getpwuid,
                                                st.st_uid).pw_name
        except KeyError:
            username = None

        try:
            groupname = self.dispatcher.threaded(grp.getgrgid,
                                                 st.st_gid).gr_name
        except RpcException:
            groupname = None

        return {
            'path': path,
            'type': get_type(st),
            'atime': datetime.utcfromtimestamp(st.st_atime),
            'mtime': datetime.utcfromtimestamp(st.st_mtime),
            'ctime': datetime.utcfromtimestamp(st.st_ctime),
            'uid': st.st_uid,
            'user': username,
            'gid': st.st_gid,
            'group': groupname,
            'permissions': {
                'acls': self.dispatcher.threaded(a.__getstate__),
                'user': username,
                'group': groupname,
                'modes': {
                    'value': st.st_mode & 0o777,
                    'user': {
                        'read': bool(st.st_mode & stat.S_IRUSR),
                        'write': bool(st.st_mode & stat.S_IWUSR),
                        'execute': bool(st.st_mode & stat.S_IXUSR)
                    },
                    'group': {
                        'read': bool(st.st_mode & stat.S_IRGRP),
                        'write': bool(st.st_mode & stat.S_IWGRP),
                        'execute': bool(st.st_mode & stat.S_IXGRP)
                    },
                    'others': {
                        'read': bool(st.st_mode & stat.S_IROTH),
                        'write': bool(st.st_mode & stat.S_IWOTH),
                        'execute': bool(st.st_mode & stat.S_IXOTH)
                    },
                }
            }
        }
Exemplo n.º 4
0
 def listdir(self, directory):
     for i in sorted(os.listdir(directory)):
         path = os.path.join(directory, i)
         stat = os.lstat(path)
         yield {
             "type": get_type(stat),
             "size": stat.st_size,
             "created_at": datetime.utcfromtimestamp(stat.st_ctime),
             "modified_at": datetime.utcfromtimestamp(stat.st_mtime),
             "name": i,
             "path": path,
         }
Exemplo n.º 5
0
    def stat(self, path):
        try:
            st = os.stat(path, follow_symlinks=False)
            a = acl.ACL(file=path)
        except OSError as err:
            raise RpcException(err.errno, str(err))

        try:
            username = self.dispatcher.threaded(pwd.getpwuid, st.st_uid).pw_name
        except KeyError:
            username = None

        try:
            groupname = self.dispatcher.threaded(grp.getgrgid, st.st_gid).gr_name
        except RpcException:
            groupname = None

        return {
            'path': path,
            'type': get_type(st),
            'atime': datetime.utcfromtimestamp(st.st_atime),
            'mtime': datetime.utcfromtimestamp(st.st_mtime),
            'ctime': datetime.utcfromtimestamp(st.st_ctime),
            'uid': st.st_uid,
            'user': username,
            'gid': st.st_gid,
            'group': groupname,
            'permissions': {
                'acl': self.dispatcher.threaded(a.__getstate__),
                'user': username,
                'group': groupname,
                'modes': {
                    'value': st.st_mode & 0o777,
                    'user': {
                        'read': bool(st.st_mode & stat.S_IRUSR),
                        'write': bool(st.st_mode & stat.S_IWUSR),
                        'execute': bool(st.st_mode & stat.S_IXUSR)
                    },
                    'group': {
                        'read': bool(st.st_mode & stat.S_IRGRP),
                        'write': bool(st.st_mode & stat.S_IWGRP),
                        'execute': bool(st.st_mode & stat.S_IXGRP)
                    },
                    'others': {
                        'read': bool(st.st_mode & stat.S_IROTH),
                        'write': bool(st.st_mode & stat.S_IWOTH),
                        'execute': bool(st.st_mode & stat.S_IXOTH)
                    },
                }
            }
        }
Exemplo n.º 6
0
def collect(datastore, path):
    try:
        st = os.stat(path, follow_symlinks=False)
    except OSError as err:
        # Can't access the file - delete index entry
        datastore.delete('fileindex', path)
        return

    volume = path.split('/')[2]
    datastore.upsert('fileindex', path, {
        'id': path,
        'volume': volume,
        'type': get_type(st),
        'atime': datetime.utcfromtimestamp(st.st_atime),
        'mtime': datetime.utcfromtimestamp(st.st_mtime),
        'ctime': datetime.utcfromtimestamp(st.st_ctime),
        'uid': st.st_uid,
        'gid': st.st_gid,
        'permissions': get_unix_permissions(st.st_mode)
    })
Exemplo n.º 7
0
    def list_dir(self, path):
        result = []
        if not os.path.isdir(path):
            raise RpcException(errno.ENOENT, 'Path {0} is not a directory'.format(path))

        for i in os.listdir(path):
            try:
                st = os.stat(os.path.join(path, i))
            except OSError:
                continue

            item = {
                'name': i,
                'type': get_type(st),
                'size': st.st_size,
                'modified': st.st_mtime
            }

            result.append(item)

        return result
Exemplo n.º 8
0
    def list_dir(self, path):
        result = []
        if not os.path.isdir(path):
            raise RpcException(errno.ENOENT, 'Path {0} is not a directory'.format(path))

        for i in os.listdir(path):
            try:
                st = os.stat(os.path.join(path, i))
            except OSError:
                continue

            item = {
                'name': i,
                'type': get_type(st),
                'size': st.st_size,
                'modified': st.st_mtime
            }

            result.append(item)

        return result