def chown(self, path, uid, gid):
     logging.error('chown is disabled.')
     raise FuseOSError(errno.EPERM)
Exemple #2
0
 def access(self, path, mode):
     full_path = self._full_path(path)
     if not os.access(full_path, mode):
         raise FuseOSError(errno.EACCES)
Exemple #3
0
 def getattr(self, path, fh=None):
     try:
         p = self.traverse(path)
     except KeyError:
         raise FuseOSError(ENOENT)
     return {attr: p[attr] for attr in p.keys() if attr != 'files'}
Exemple #4
0
 def rmdir(self, path):
     node = self.getNode(path)
     if node and node.props.get('islocked', False):
         logger.debug("%s is locked." % path)
         raise FuseOSError(EPERM)
     self.client.delete(path)
Exemple #5
0
 def lolnop(*args, **kwargs):
     raise FuseOSError(EACCES)
Exemple #6
0
 def getxattr(self, path, name, position=0):
     return ''
     raise FuseOSError(ENOATTR)
     """
Exemple #7
0
 def release(self, fh):
     fh = getattr(fh, 'fh', fh)
     if fh not in self._fd:
         raise FuseOSError(EBADF)
     self._fd.pop(fh).close()
     heappush(self._fh, fh)
Exemple #8
0
 def mkdir(self, path: FsPath, mode: int):
     if is_banned(path.name):
         raise FuseOSError(errno.EACCES)
     self.fs_access.folder_create(path)
     return 0
Exemple #9
0
 def rmdir(self, path):
     if path.count('/') == 1:
         tag = path[1:]
         self.tracker.delete_tag(tag)
     else:
         raise FuseOSError(EROFS)
 def getattr(self, path, fh=None):
     metainfo = self.metaWrapper(path,None,'get')
     if metainfo == False:
         raise FuseOSError(ENOENT)
     return metainfo
Exemple #11
0
 def create(self, path: FsPath, mode: int):
     if is_banned(path.name):
         raise FuseOSError(errno.EACCES)
     _, fd = self.fs_access.file_create(path, open=True)
     return fd
Exemple #12
0
 def getattr(self, path, fh=None):
     print("getattr")
     ret = send_and_recv(sock, DFS_GETATTR, [path, fh])
     if ret == False:
         raise FuseOSError(errno.ENOENT)
     return ret
Exemple #13
0
 def access(self, path, mode):
     print("access")
     if not send_and_recv(sock, DFS_ACCESS, [path, mode]):
         raise FuseOSError(errno.EACCES)
Exemple #14
0
 def getattr(self, path, fh=None):
     # print "enters getattr", path
     if path in self.cache:
         return self.cache[path].stat()
     raise FuseOSError(errno.ENOENT)
Exemple #15
0
    def file_upload(self, path):
        if path not in self.files:
            raise FuseOSError(EIO)

        fileObject = self.file_get(path)
        if fileObject['modified'] == False:
            return True

        print 'uploading: ' + path

        f = fileObject['object']

        # obtain the size of the file
        f.seek(0, os.SEEK_END)
        size = f.tell()
        f.seek(0)

        parts = self.copy_api.partify(f, size)

        # obtain list of parts that need to be sent
        response = self.copy_api.part_request('has_parts', parts)

        if 'send_parts' not in response:
            raise FuseOSError(EIO)

        # build array of parts that need to be sent
        need_parts = {}
        for need_part in response['send_parts']:
            need_parts[need_part['fingerprint'] + '-' +
                       need_part['size']] = True

        # send the missing parts
        send_parts = {}
        for i in range(0, len(parts)):
            if parts[i]['fingerprint'] + '-' + str(
                    parts[i]['size']) in need_parts:
                send_parts[len(send_parts)] = parts[i]
        response = self.copy_api.part_request('send_parts', send_parts)

        # trap any errors
        if (response == False or response['result'] != 'success'):
            raise FuseOSError(EIO)

        # remove data from parts (already sent)
        for i in range(0, len(parts)):
            del parts[i]['data']

        # send file metadata
        params = {'meta': {}}
        params['meta'][0] = {
            'action': 'create',
            'object_type': 'file',
            'path': path,
            'size': size,
            'parts': parts
        }
        response = self.copy_api.copyrequest('/update_objects', params, True)

        # trap any errors
        if response['result'] != 'success':
            raise FuseOSError(EIO)

        fileObject['modified'] = False
Exemple #16
0
 def mkdir(self, path, mode):
     if path.count('/') == 1:
         self.tracker.create_tag(path[1:])
     else:
         raise FuseOSError(EROFS)
Exemple #17
0
 def read(self, path, size, offset, fh):
     if not self.file_exists(path):
         raise FuseOSError(ENOENT)
     file_content = self.get_post_file_content(path)
     # print(content)
     return file_content.encode("utf-8")[offset:offset + size]
Exemple #18
0
 def _access(p):
     if not os.access(p, mode):
         raise FuseOSError(errno.EACCES)
Exemple #19
0
 def link(self, path, source):
     raise FuseOSError(ENOTSUP)
Exemple #20
0
    def symlink(self, target, source):

        raise FuseOSError(EPERM)
Exemple #21
0
    def open(self, path, flags, *mode):
        """Open file with the desired modes

        Here we return a handle to the cached version of the file
        which is updated if older and out of sync with VOSpace.

        """

        logger.debug("Opening %s with flags %s" % (path, flag2mode(flags)))
        node = None

        # according to man for open(2), flags must contain one of O_RDWR,
        # O_WRONLY or O_RDONLY. Because O_RDONLY=0 and options other than
        # O_RDWR, O_WRONLY and O_RDONLY may be present,
        # readonly = (flags == O_RDONLY) and readonly = (flags | O_RDONLY)
        # won't work. The only way to detect if it's a read only is to check
        # whether the other two flags are absent.
        read_only = ((flags & (os.O_RDWR | os.O_WRONLY)) == 0)

        must_exist = not ((flags & os.O_CREAT) == os.O_CREAT)
        cache_file_attrs = self.cache.getAttr(path)
        if cache_file_attrs is None and not read_only:
            # file in the cache not in the process of being modified.
            # see if this node already exists in the cache; if not get info
            # from vospace
            try:
                node = self.get_node(path)
            except OSError as e:
                if e.errno == 404:
                    # file does not exist
                    if not flags & os.O_CREAT:
                        # file doesn't exist unless created
                        raise FuseOSError(ENOENT)
                else:
                    raise FuseOSError(e.errno)

        # check if this file is locked, if locked on vospace then don't open
        locked = False

        if node and node.props.get('islocked', False):
            logger.debug("%s is locked." % path)
            locked = True

        if not read_only and node and not locked:
            if node.type == "vos:DataNode":
                parent_node = self.get_node(os.path.dirname(path),
                                            force=False,
                                            limit=1)
                if parent_node.props.get('islocked', False):
                    logger.debug("%s is locked by parent node." % path)
                    locked = True
            elif node.type == "vos:LinkNode":
                try:
                    # sometimes target_nodes aren't internal... so then not
                    # locked
                    target_node = self.get_node(node.target,
                                                force=False,
                                                limit=1)
                    if target_node.props.get('islocked', False):
                        logger.debug("{0} target node is locked.".format(path))
                        locked = True
                    else:
                        target_parent_node = self.get_node(os.path.dirname(
                            node.target),
                                                           force=False,
                                                           limit=1)
                        if target_parent_node.props.get('islocked', False):
                            logger.debug(
                                "{0} parent node is locked.".format(path))
                            locked = True
                except Exception as lock_exception:
                    logger.warn("Error while checking for lock: {0}".format(
                        str(lock_exception)))
                    pass

        if locked and not read_only:
            # file is locked, cannot write
            e = OSError(EPERM)
            e.filename = path
            e.strerror = "Cannot write to locked file"
            logger.debug("{0}".format(e))
            raise e

        my_proxy = MyIOProxy(self, path)
        if node is not None:
            my_proxy.set_size(int(node.props.get('length')))
            my_proxy.set_md5(node.props.get('MD5'))

        logger.debug("IO Proxy initialized:{0}  in backing.".format(my_proxy))

        # new file in cache library or if no node information (node not in vospace).
        handle = self.cache.open(path, flags & os.O_WRONLY != 0, must_exist,
                                 my_proxy, self.cache_nodes)

        logger.debug("Creating file:{0}  in backing.".format(path))

        if flags & os.O_TRUNC != 0:
            handle.truncate(0)
        if node is not None:
            handle.setHeader(my_proxy.getSize(), my_proxy.get_md5())
        return HandleWrapper(handle, read_only).get_id()
Exemple #22
0
    def readlink(self, filepath):

        raise FuseOSError(EPERM)
 def access(self, path, mode):
     print('[access] {}'.format(path))
     full_path = self._full_path(path)
     if not os.access(full_path, mode):
         raise FuseOSError(errno.EACCES)
Exemple #24
0
    def unlink(self, file_path):
        """Remove a file."""
        # TODO: Change to simply move to "trash". Have a FUSE option to elect this
        # behavior.
        path_relations = PathRelations.get_instance()

        try:
            entry_clause = path_relations.get_clause_from_path(file_path)
        except GdNotFoundError:
            _logger.exception("Could not process [%s] (unlink).", file_path)
            raise FuseOSError(ENOENT)
        except:
            _logger.exception(
                "Could not get clause from file-path [%s] "
                "(unlink).", file_path)

            raise FuseOSError(EIO)

        if not entry_clause:
            _logger.error("Path [%s] does not exist for unlink().", file_path)

            raise FuseOSError(ENOENT)

        entry_id = entry_clause[CLAUSE_ID]
        normalized_entry = entry_clause[CLAUSE_ENTRY]

        # Check if a directory.

        if normalized_entry.is_directory:
            _logger.error(
                "Can not unlink() directory [%s] with ID [%s]. "
                "Must be file.", file_path, entry_id)

            raise FuseOSError(errno.EISDIR)

        # Remove online. Complements local removal (if not found locally, a
        # follow-up request checks online).

        gd = get_gdrive()

        try:
            gd.remove_entry(normalized_entry)
        except NameError:
            raise FuseOSError(ENOENT)
        except:
            _logger.exception("Could not remove file [%s] with ID [%s].",
                              file_path, entry_id)

            raise FuseOSError(EIO)

        # Remove from cache. Will no longer be able to be found, locally.
        PathRelations.get_instance().remove_entry_all(entry_id)

        # Remove from among opened-files.

        om = gdrivefs.opened_file.get_om()

        try:
            opened_file = om.remove_by_filepath(file_path)
        except:
            _logger.exception(
                "There was an error while removing all "
                "opened-file instances for file [%s] "
                "(remove).", file_path)
            raise FuseOSError(EIO)
Exemple #25
0
 def access(self, path, mode):
     Log('access', path, mode, level=1)
     full_path = self._full_path(path)
     if not os.access(full_path, mode):
         raise FuseOSError(errno.EACCES)
Exemple #26
0
 def access(self, path, mode):
     if not os.access(path, mode):
         raise FuseOSError(EACCES)
Exemple #27
0
 def rmdir(self, path):
     p, tar = self.traverseparent(path)
     if len(p['files'][tar]['files']) > 0:
         raise FuseOSError(ENOTEMPTY)
     p['files'].pop(tar)
     p['st_nlink'] -= 1
Exemple #28
0
 def get_by_path(self, path):
     obj = self.pages.get(path, self.dirs.get(path))
     if not obj:
         raise FuseOSError(ENOENT)
     return obj
    def getattr(self, path, fh=None):
        if path not in self.files:
            raise FuseOSError(ENOENT)

        return self.files[path]
 def chmod(self, path, mode):
     if mode == self.note_stat['st_mode']:
         return 0
     else:
         logging.error('chmod is disabled.')
         raise FuseOSError(errno.EPERM)