예제 #1
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)
예제 #2
0
파일: gdfuse.py 프로젝트: bsavelev/GDriveFS
    def truncate(self, filepath, length, fh=None):
        if fh is not None:
            om = gdrivefs.gdfs.opened_file.get_om()

            try:
                opened_file = om.get_by_fh(fh)
            except:
                _logger.exception("Could not retrieve OpenedFile for handle " "with ID (%d) (truncate).", fh)

                raise FuseOSError(EIO)

            _logger.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:
                _logger.exception("Could not fetch normalized entry with ID " "[%s] for truncate with FH.", entry_id)
                raise

            opened_file.truncate(length)
        else:
            (entry, path, filename) = get_entry_or_raise(filepath)

        gd = get_gdrive()

        try:
            entry = gd.truncate(entry)
        except:
            _logger.exception("Could not truncate entry [%s].", entry)
            raise FuseOSError(EIO)
예제 #3
0
    def truncate(self, filepath, length, fh=None):
        if fh is not None:
            om = gdrivefs.gdfs.opened_file.get_om()

            try:
                opened_file = om.get_by_fh(fh)
            except:
                _logger.exception(
                    "Could not retrieve OpenedFile for handle "
                    "with ID (%d) (truncate).", fh)

                raise FuseOSError(EIO)

            _logger.debug("Truncating and clearing FH: %s", opened_file)

            opened_file.reset_state()

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

            opened_file.truncate(length)
        else:
            (entry, path, filename) = get_entry_or_raise(filepath)

        gd = get_gdrive()

        try:
            entry = gd.truncate(entry)
        except:
            _logger.exception("Could not truncate entry [%s].", entry)
            raise FuseOSError(EIO)
예제 #4
0
파일: gdfuse.py 프로젝트: geonmo/GDriveFS
    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)
예제 #5
0
    def __init__(self, entry_id, path, filename, is_hidden, mime_type):

        self.__log = logging.getLogger().getChild('OpenFile')

        self.__log.info("Opened-file object created for entry-ID [%s] and "
                        "path (%s)." % (entry_id, path))

        self.__entry_id = entry_id
        self.__path = path
        self.__filename = filename
        self.__is_hidden = is_hidden
        
        self.__mime_type = mime_type
        self.__cache = EntryCache.get_instance().cache

        self.reset_state()
예제 #6
0
    def __init__(self, entry_id, path, filename, is_hidden, mime_type):

        self.__log = logging.getLogger().getChild('OpenFile')

        self.__log.info("Opened-file object created for entry-ID [%s] and "
                        "path (%s)." % (entry_id, path))

        self.__entry_id = entry_id
        self.__path = path
        self.__filename = filename
        self.__is_hidden = is_hidden

        self.__mime_type = mime_type
        self.__cache = EntryCache.get_instance().cache

        self.reset_state()
예제 #7
0
    def __init__(self, entry_id, path, filename, is_hidden, mime_type):

        self.__log = logging.getLogger().getChild('OpenFile')

        self.__log.info("Opened-file object created for entry-ID [%s] and "
                        "path (%s)." % (entry_id, path))
# TODO: Refactor this to being all obfuscated property names.
        self.__entry_id = entry_id
        self.__path = path
        self.__filename = filename
        self.__is_hidden = is_hidden
        
        self.__mime_type = mime_type
        self.__cache = EntryCache.get_instance().cache
        self.__buffer = None
        self.__is_loaded = False
        self.__is_dirty = False
예제 #8
0
    def __init__(self, entry_id, path, filename, is_hidden, mime_type):

        self.__log = logging.getLogger().getChild('OpenFile')

        self.__log.info("Opened-file object created for entry-ID [%s] and "
                        "path (%s)." % (entry_id, path))
# TODO: Refactor this to being all obfuscated property names.
        self.__entry_id = entry_id
        self.__path = path
        self.__filename = filename
        self.__is_hidden = is_hidden
        
        self.__mime_type = mime_type
        self.__cache = EntryCache.get_instance().cache
        self.__buffer = None
        self.__is_loaded = False
        self.__is_dirty = False
예제 #9
0
    def __init__(self, entry_id, path, filename, is_hidden, mime_type):
        # TODO(dustin): Until we can gracely orchestrate concurrent handles on the same
        #               entry, we can't allow it. This is referenced, just below.
        with _OPENED_ENTRIES_LOCK:
            assert entry_id not in _OPENED_ENTRIES, \
                   "Access to the same file from multiple file-handles is "\
                   "not currently supported."

            _OPENED_ENTRIES.add(entry_id)

        _LOGGER.info(
            "Opened-file object created for entry-ID [%s] and path "
            "(%s).", entry_id, path)

        self.__entry_id = entry_id
        self.__path = path
        self.__filename = filename
        self.__is_hidden = is_hidden

        self.__mime_type = mime_type
        self.__cache = EntryCache.get_instance().cache

        self.__is_loaded = False
        self.__is_dirty = False

        # Use the monotonically incremented `opened_count` to produce a unique
        # temporary filepath.

        om = get_om()
        self.__temp_filepath = \
            os.path.join(om.temp_path, str(om.opened_count))

        self.__fh = None

        # We need to load this up-front. Since we can't do partial updates, we
        # have to keep one whole, local copy, apply updates to it, and then
        # post it on flush.
        # TODO(dustin): Until we finish working on the download-agent so that we can
        #               have a way to orchestrate concurrent handles on the same file,
        #               we'll just have to accept the fact that concurrent access will
        #               require multiple downloads of the same file to multiple
        #               temporary files (one for each).
        self.__load_base_from_remote()
예제 #10
0
    def __init__(self, entry_id, path, filename, is_hidden, mime_type):
# TODO(dustin): Until we can gracely orchestrate concurrent handles on the same 
#               entry, we can't allow it. This is referenced, just below.
        with _OPENED_ENTRIES_LOCK:
            assert entry_id not in _OPENED_ENTRIES, \
                   "Access to the same file from multiple file-handles is "\
                   "not currently supported."

            _OPENED_ENTRIES.add(entry_id)

        _LOGGER.info("Opened-file object created for entry-ID [%s] and path "
                     "(%s).", entry_id, path)

        self.__entry_id = entry_id
        self.__path = path
        self.__filename = filename
        self.__is_hidden = is_hidden
        
        self.__mime_type = mime_type
        self.__cache = EntryCache.get_instance().cache

        self.__is_loaded = False
        self.__is_dirty = False

        # Use the monotonically incremented `opened_count` to produce a unique 
        # temporary filepath.

        om = get_om()
        self.__temp_filepath = \
            os.path.join(om.temp_path, str(om.opened_count))

        self.__fh = None

        # We need to load this up-front. Since we can't do partial updates, we 
        # have to keep one whole, local copy, apply updates to it, and then 
        # post it on flush.
# TODO(dustin): Until we finish working on the download-agent so that we can 
#               have a way to orchestrate concurrent handles on the same file, 
#               we'll just have to accept the fact that concurrent access will 
#               require multiple downloads of the same file to multiple 
#               temporary files (one for each).
        self.__load_base_from_remote()
예제 #11
0
파일: gdfuse.py 프로젝트: He1my/GDriveFS
    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)
예제 #12
0
파일: gdfuse.py 프로젝트: HostSuki/GDriveFS
    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)
예제 #13
0
def get_by_id(_id):
    cache = EntryCache.get_instance().cache

    return cache.get(_id)
예제 #14
0
def get_by_id(_id):
    cache = EntryCache.get_instance().cache

    return cache.get(_id)