From 6a863611099f12830603f9464bf3838d76fb3b00 Mon Sep 17 00:00:00 2001 From: Danilo Poccia Date: Wed, 30 Apr 2014 17:38:23 +0200 Subject: [PATCH] Removed use of FileIO in disk cache. --- yas3fs/__init__.py | 18 ++++++++++-------- yas3fs/_version.py | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/yas3fs/__init__.py b/yas3fs/__init__.py index c6f3f4c..2c0584c 100755 --- a/yas3fs/__init__.py +++ b/yas3fs/__init__.py @@ -166,21 +166,21 @@ def __init__(self, cache, store, path): filename = self.cache.get_cache_filename(self.path) if os.path.isfile(filename): # There's a file already there - self.content = io.FileIO(filename, mode='rb+') + self.content = open(filename, mode='rb+') self.update_size() self.content.close() self.set('new', None) # Not sure it is the latest version # Now search for an etag file etag_filename = self.cache.get_cache_etags_filename(self.path) if os.path.isfile(etag_filename): - with open(etag_filename, 'r') as etag_file: + with open(etag_filename, mode='r') as etag_file: self.etag = etag_file.read() previous_file = True if not previous_file: logger.debug("creating new cache file '%s'" % filename) with self.cache.disk_lock: create_dirs_for_file(filename) - open(filename, 'w').close() # To create an empty file (and overwrite a previous file) + open(filename, mode='w').close() # To create an empty file (and overwrite a previous file) logger.debug("created new cache file '%s'" % filename) self.content = None # Not open, yet else: @@ -192,7 +192,7 @@ def open(self): if not self.has('open'): if self.store == 'disk': filename = self.cache.get_cache_filename(self.path) - self.content = io.FileIO(filename, mode='rb+') + self.content = open(filename, mode='rb+') self.inc('open') def close(self): with self.get_lock(): @@ -209,11 +209,13 @@ def update_etag(self, new_etag): filename = self.cache.get_cache_etags_filename(self.path) with self.cache.disk_lock: create_dirs_for_file(filename) - with open(filename, 'w') as etag_file: + with open(filename, mode='w') as etag_file: etag_file.write(new_etag) def get_current_size(self): if self.content: - return self.content.seek(0,2) + with self.get_lock(): + self.content.seek(0,2) + return self.content.tell() else: return 0 # There's no content... def update_size(self, final=False): @@ -310,7 +312,7 @@ def rename(self, new_path): with self.cache.disk_lock: remove_empty_dirs_for_file(etag_filename) if self.content: - self.content = io.FileIO(new_filename, mode='rb+') + self.content = open(new_filename, mode='rb+') self.path = new_path class FSCache(): @@ -1949,7 +1951,7 @@ def write(self, path, new_data, offset, fh=None): data = self.cache.get(path, 'data') with data.get_lock(): if not data.content: - logger.debug("write awake '%s' '%i' '%i' '%s' no content" % (path, len(new_data), offset, fh)) + logger.info("write awake '%s' '%i' '%i' '%s' no content" % (path, len(new_data), offset, fh)) return 0 logger.debug("write '%s' '%i' '%i' '%s' '%s' content" % (path, len(new_data), offset, fh, data.content)) data.content.seek(offset) diff --git a/yas3fs/_version.py b/yas3fs/_version.py index 04188a1..36a511e 100644 --- a/yas3fs/_version.py +++ b/yas3fs/_version.py @@ -1 +1 @@ -__version__ = '2.2.0' +__version__ = '2.2.1'