Esempio n. 1
0
    def create(self, raw_filepath, mode):
        """Create a new file. This always precedes a write."""

        try:
            fh = OpenedManager.get_instance().get_new_handle()
        except:
            _logger.exception("Could not acquire file-handle for create of "
                              "[%s]." % (raw_filepath))
            raise FuseOSError(EIO)

        (entry, path, filename, mime_type) = self.__create(raw_filepath)

        try:
            opened_file = OpenedFile(entry.id, path, filename,
                                     not entry.is_visible, mime_type)
        except:
            _logger.exception("Could not create OpenedFile object for "
                              "created file.")
            raise FuseOSError(EIO)

        try:
            OpenedManager.get_instance().add(opened_file, fh=fh)
        except:
            _logger.exception("Could not register OpenedFile for created "
                              "file.")
            raise FuseOSError(EIO)

        return fh
Esempio n. 2
0
    def create(self, raw_filepath, mode):
        """Create a new file. This always precedes a write."""

        try:
            fh = OpenedManager.get_instance().get_new_handle()
        except:
            _logger.exception("Could not acquire file-handle for create of "
                                 "[%s]." % (raw_filepath))
            raise FuseOSError(EIO)

        (entry, path, filename, mime_type) = self.__create(raw_filepath)

        try:
            opened_file = OpenedFile(entry.id, path, filename, 
                                     not entry.is_visible, mime_type)
        except:
            _logger.exception("Could not create OpenedFile object for "
                                 "created file.")
            raise FuseOSError(EIO)

        try:
            OpenedManager.get_instance().add(opened_file, fh=fh)
        except:
            _logger.exception("Could not register OpenedFile for created "
                                 "file.")
            raise FuseOSError(EIO)

        return fh
Esempio n. 3
0
    def release(self, filepath, fh):
        """Close a file."""

        try:
            OpenedManager.get_instance().remove_by_fh(fh)
        except:
            self.__log.exception("Could not remove OpenedFile for handle with "
                                 "ID (%d) (release)." % (fh))
            raise FuseOSError(EIO)
Esempio n. 4
0
    def release(self, filepath, fh):
        """Close a file."""

        try:
            OpenedManager.get_instance().remove_by_fh(fh)
        except:
            self.__log.exception("Could not remove OpenedFile for handle with "
                                 "ID (%d) (release)." % (fh))
            raise FuseOSError(EIO)
Esempio n. 5
0
    def open(self, filepath, flags):
# TODO: Fail if does not exist and the mode/flags is read only.

        self.__log.debug("Building OpenedFile object for file being opened.")

        try:
            opened_file = OpenedFile.create_for_requested_filepath(filepath)
        except GdNotFoundError:
            self.__log.exception("Could not create handle for requested [%s] "
                                 "(open)." % (filepath))
            raise FuseOSError(ENOENT)
        except:
            self.__log.exception("Could not create OpenedFile object for "
                                 "opened filepath [%s]." % (filepath))
            raise FuseOSError(EIO)

        self.__log.debug("Created OpenedFile object [%s]." % (opened_file))

        try:
            fh = OpenedManager.get_instance().add(opened_file)
        except:
            self.__log.exception("Could not register OpenedFile for opened "
                                 "file.")
            raise FuseOSError(EIO)

        self.__log.debug("File opened.")

        return fh
Esempio n. 6
0
    def truncate(self, filepath, length, fh=None):
        if fh is not None:
            try:
                opened_file = OpenedManager.get_instance().get_by_fh(fh)
            except:
                _logger.exception("Could not retrieve OpenedFile for handle "
                                  "with ID (%d) (truncate)." % (fh))
                raise FuseOSError(EIO)

            opened_file.reset_state()

            entry_id = opened_file.entry_id
            cache = EntryCache.get_instance().cache

            try:
                entry = cache.get(entry_id)
            except:
                _logger.exception("Could not fetch normalized entry with "
                                  "ID [%s] for truncate with FH." % (entry_id))
                raise
        else:
            (entry, path, filename) = get_entry_or_raise(filepath)

        try:
            entry = drive_proxy('truncate', normalized_entry=entry)
        except:
            _logger.exception("Could not truncate entry [%s]." % (entry))
            raise FuseOSError(EIO)
Esempio n. 7
0
    def truncate(self, filepath, length, fh=None):
        if fh is not None:
            try:
                opened_file = OpenedManager.get_instance().get_by_fh(fh)
            except:
                _logger.exception("Could not retrieve OpenedFile for handle "
                                     "with ID (%d) (truncate)." % (fh))
                raise FuseOSError(EIO)

            opened_file.reset_state()

            entry_id = opened_file.entry_id
            cache = EntryCache.get_instance().cache

            try:
                entry = cache.get(entry_id)
            except:
                _logger.exception("Could not fetch normalized entry with "
                                     "ID [%s] for truncate with FH." % 
                                     (entry_id))
                raise
        else:
            (entry, path, filename) = get_entry_or_raise(filepath)

        try:
            entry = drive_proxy('truncate', normalized_entry=entry)
        except:
            _logger.exception("Could not truncate entry [%s]." % (entry))
            raise FuseOSError(EIO)
Esempio n. 8
0
    def open(self, filepath, flags):
        # TODO: Fail if does not exist and the mode/flags is read only.

        self.__log.debug("Building OpenedFile object for file being opened.")

        try:
            opened_file = OpenedFile.create_for_requested_filepath(filepath)
        except GdNotFoundError:
            self.__log.exception("Could not create handle for requested [%s] "
                                 "(open)." % (filepath))
            raise FuseOSError(ENOENT)
        except:
            self.__log.exception("Could not create OpenedFile object for "
                                 "opened filepath [%s]." % (filepath))
            raise FuseOSError(EIO)

        self.__log.debug("Created OpenedFile object [%s]." % (opened_file))

        try:
            fh = OpenedManager.get_instance().add(opened_file)
        except:
            self.__log.exception("Could not register OpenedFile for opened "
                                 "file.")
            raise FuseOSError(EIO)

        self.__log.debug("File opened.")

        return fh
Esempio n. 9
0
    def flush(self, filepath, fh):

        try:
            opened_file = OpenedManager.get_instance().get_by_fh(fh=fh)
        except:
            self.__log.exception("Could not get OpenedFile (flush).")
            raise FuseOSError(EIO)

        try:
            opened_file.flush()
        except:
            self.__log.exception("Could not flush local updates.")
            raise FuseOSError(EIO)
Esempio n. 10
0
    def flush(self, filepath, fh):
        
        try:
            opened_file = OpenedManager.get_instance().get_by_fh(fh=fh)
        except:
            self.__log.exception("Could not get OpenedFile (flush).")
            raise FuseOSError(EIO)

        try:
            opened_file.flush()
        except:
            self.__log.exception("Could not flush local updates.")
            raise FuseOSError(EIO)
Esempio n. 11
0
    def create(self, raw_filepath, mode):
        """Create a new file. This always precedes a write."""

        self.__log.debug("Acquiring file-handle.")

        try:
            fh = OpenedManager.get_instance().get_new_handle()
        except:
            self.__log.exception("Could not acquire file-handle for create of "
                                 "[%s]." % (raw_filepath))
            raise FuseOSError(EIO)

        (entry, path, filename, mime_type) = self.__create(raw_filepath)

        self.__log.debug("Building OpenedFile object for created file.")

        try:
            opened_file = OpenedFile(entry.id, path, filename,
                                     not entry.is_visible, mime_type)
        except:
            self.__log.exception("Could not create OpenedFile object for "
                                 "created file.")
            raise FuseOSError(EIO)

        self.__log.debug("Registering OpenedFile object with handle (%d), "
                         "path [%s], and ID [%s]." %
                         (fh, raw_filepath, entry.id))

        try:
            OpenedManager.get_instance().add(opened_file, fh=fh)
        except:
            self.__log.exception("Could not register OpenedFile for created "
                                 "file.")
            raise FuseOSError(EIO)

        self.__log.debug("File created, opened, and completely registered.")

        return fh
Esempio n. 12
0
    def create(self, raw_filepath, mode):
        """Create a new file. This always precedes a write."""

        self.__log.debug("Acquiring file-handle.")

        try:
            fh = OpenedManager.get_instance().get_new_handle()
        except:
            self.__log.exception("Could not acquire file-handle for create of "
                                 "[%s]." % (raw_filepath))
            raise FuseOSError(EIO)

        (entry, path, filename, mime_type) = self.__create(raw_filepath)

        self.__log.debug("Building OpenedFile object for created file.")

        try:
            opened_file = OpenedFile(entry.id, path, filename, 
                                     not entry.is_visible, mime_type)
        except:
            self.__log.exception("Could not create OpenedFile object for "
                                 "created file.")
            raise FuseOSError(EIO)

        self.__log.debug("Registering OpenedFile object with handle (%d), "
                         "path [%s], and ID [%s]." % 
                         (fh, raw_filepath, entry.id))

        try:
            OpenedManager.get_instance().add(opened_file, fh=fh)
        except:
            self.__log.exception("Could not register OpenedFile for created "
                                 "file.")
            raise FuseOSError(EIO)

        self.__log.debug("File created, opened, and completely registered.")

        return fh
Esempio n. 13
0
    def write(self, filepath, data, offset, fh):
        try:
            opened_file = OpenedManager.get_instance().get_by_fh(fh=fh)
        except:
            _logger.exception("Could not get OpenedFile (write).")
            raise FuseOSError(EIO)

        try:
            opened_file.add_update(offset, data)
        except:
            _logger.exception("Could not queue file-update.")
            raise FuseOSError(EIO)

        return len(data)
Esempio n. 14
0
    def read(self, raw_path, length, offset, fh):

        try:
            opened_file = OpenedManager.get_instance().get_by_fh(fh)
        except:
            self.__log.exception("Could not retrieve OpenedFile for handle "
                                 "with ID (%d) (read)." % (fh))
            raise FuseOSError(EIO)

        try:
            return opened_file.read(offset, length)
        except:
            self.__log.exception("Could not read data.")
            raise FuseOSError(EIO)
Esempio n. 15
0
    def read(self, raw_path, length, offset, fh):

        try:
            opened_file = OpenedManager.get_instance().get_by_fh(fh)
        except:
            self.__log.exception("Could not retrieve OpenedFile for handle "
                                 "with ID (%d) (read)." % (fh))
            raise FuseOSError(EIO)

        try:
            return opened_file.read(offset, length)
        except:
            self.__log.exception("Could not read data.")
            raise FuseOSError(EIO)
Esempio n. 16
0
    def write(self, filepath, data, offset, fh):
        try:
            opened_file = OpenedManager.get_instance().get_by_fh(fh=fh)
        except:
            _logger.exception("Could not get OpenedFile (write).")
            raise FuseOSError(EIO)

        try:
            opened_file.add_update(offset, data)
        except:
            _logger.exception("Could not queue file-update.")
            raise FuseOSError(EIO)

        return len(data)
Esempio n. 17
0
    def write(self, filepath, data, offset, fh):

        self.__log.debug("Write data length is (%d)." % (len(data)))

        try:
            opened_file = OpenedManager.get_instance().get_by_fh(fh=fh)
        except:
            self.__log.exception("Could not get OpenedFile (write).")
            raise FuseOSError(EIO)

        try:
            opened_file.add_update(offset, data)
        except:
            self.__log.exception("Could not queue file-update.")
            raise FuseOSError(EIO)

        self.__log.debug("Write queued.")

        return len(data)
Esempio n. 18
0
    def write(self, filepath, data, offset, fh):

        self.__log.debug("Write data length is (%d)." % (len(data)))

        try:
            opened_file = OpenedManager.get_instance().get_by_fh(fh=fh)
        except:
            self.__log.exception("Could not get OpenedFile (write).")
            raise FuseOSError(EIO)

        try:
            opened_file.add_update(offset, data)
        except:
            self.__log.exception("Could not queue file-update.")
            raise FuseOSError(EIO)

        self.__log.debug("Write queued.")

        return len(data)
Esempio n. 19
0
    def truncate(self, filepath, length, fh=None):
        self.__log.debug("Truncating file-path [%s] with FH [%s]." %
                         (filepath, fh))

        if fh is not None:
            self.__log.debug("Doing truncate by FH (%d)." % (fh))

            try:
                opened_file = OpenedManager.get_instance().get_by_fh(fh)
            except:
                self.__log.exception(
                    "Could not retrieve OpenedFile for handle "
                    "with ID (%d) (truncate)." % (fh))
                raise FuseOSError(EIO)

            self.__log.debug("Truncating and clearing FH: %s" % (opened_file))

            opened_file.reset_state()

            entry_id = opened_file.entry_id
            cache = EntryCache.get_instance().cache

            try:
                entry = cache.get(entry_id)
            except:
                self.__log.exception("Could not fetch normalized entry with "
                                     "ID [%s] for truncate with FH." %
                                     (entry_id))
                raise
        else:
            (entry, path, filename) = self.__get_entry_or_raise(filepath)

        self.__log.debug("Sending truncate request for [%s]." % (entry))

        try:
            entry = drive_proxy('truncate', normalized_entry=entry)
        except:
            self.__log.exception("Could not truncate entry [%s]." % (entry))
            raise FuseOSError(EIO)
Esempio n. 20
0
    def truncate(self, filepath, length, fh=None):
        self.__log.debug("Truncating file-path [%s] with FH [%s]." % 
                         (filepath, fh))

        if fh is not None:
            self.__log.debug("Doing truncate by FH (%d)." % (fh))
        
            try:
                opened_file = OpenedManager.get_instance().get_by_fh(fh)
            except:
                self.__log.exception("Could not retrieve OpenedFile for handle "
                                     "with ID (%d) (truncate)." % (fh))
                raise FuseOSError(EIO)

            self.__log.debug("Truncating and clearing FH: %s" % (opened_file))

            opened_file.reset_state()

            entry_id = opened_file.entry_id
            cache = EntryCache.get_instance().cache

            try:
                entry = cache.get(entry_id)
            except:
                self.__log.exception("Could not fetch normalized entry with "
                                     "ID [%s] for truncate with FH." % 
                                     (entry_id))
                raise
        else:
            (entry, path, filename) = self.__get_entry_or_raise(filepath)

        self.__log.debug("Sending truncate request for [%s]." % (entry))

        try:
            entry = drive_proxy('truncate', normalized_entry=entry)
        except:
            self.__log.exception("Could not truncate entry [%s]." % (entry))
            raise FuseOSError(EIO)
Esempio n. 21
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()

        self.__log.debug("Removing file [%s]." % (file_path))

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

        if not entry_clause:
            self.__log.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.

        self.__log.debug("Ensuring it is a file (not a directory).")

        if normalized_entry.is_directory:
            self.__log.error("Can not unlink() directory [%s] with ID [%s]. "
                             "Must be file.", file_path, entry_id)
            raise FuseOSError(errno.EISDIR)

        self.__log.debug("Doing remove of directory [%s] with ID [%s]." % 
                         (file_path, entry_id))

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

        try:
            drive_proxy('remove_entry', normalized_entry=normalized_entry)
        except (NameError):
            raise FuseOSError(ENOENT)
        except:
            self.__log.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.

        self.__log.debug("Removing all trace of entry [%s] from cache "
                         "(unlink)." % (normalized_entry))

        try:
            PathRelations.get_instance().remove_entry_all(entry_id)
        except:
            self.__log.exception("There was a problem removing entry [%s] "
                                 "from the caches." % (normalized_entry))
            raise

        # Remove from among opened-files.

        self.__log.debug("Removing all opened-files for [%s]." % (file_path))

        try:
            opened_file = OpenedManager.get_instance().\
                            remove_by_filepath(file_path)
        except:
            self.__log.exception("There was an error while removing all "
                                 "opened-file instances for file [%s] "
                                 "(remove)." % (file_path))
            raise FuseOSError(EIO)

        self.__log.debug("File removal complete.")
Esempio n. 22
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()

        self.__log.debug("Removing file [%s]." % (file_path))

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

        if not entry_clause:
            self.__log.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.

        self.__log.debug("Ensuring it is a file (not a directory).")

        if normalized_entry.is_directory:
            self.__log.error(
                "Can not unlink() directory [%s] with ID [%s]. "
                "Must be file.", file_path, entry_id)
            raise FuseOSError(errno.EISDIR)

        self.__log.debug("Doing remove of directory [%s] with ID [%s]." %
                         (file_path, entry_id))

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

        try:
            drive_proxy('remove_entry', normalized_entry=normalized_entry)
        except (NameError):
            raise FuseOSError(ENOENT)
        except:
            self.__log.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.

        self.__log.debug("Removing all trace of entry [%s] from cache "
                         "(unlink)." % (normalized_entry))

        try:
            PathRelations.get_instance().remove_entry_all(entry_id)
        except:
            self.__log.exception("There was a problem removing entry [%s] "
                                 "from the caches." % (normalized_entry))
            raise

        # Remove from among opened-files.

        self.__log.debug("Removing all opened-files for [%s]." % (file_path))

        try:
            opened_file = OpenedManager.get_instance().\
                            remove_by_filepath(file_path)
        except:
            self.__log.exception("There was an error while removing all "
                                 "opened-file instances for file [%s] "
                                 "(remove)." % (file_path))
            raise FuseOSError(EIO)

        self.__log.debug("File removal complete.")