Skip to content

Commit

Permalink
Removed use of FileIO in disk cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
danilop committed Apr 30, 2014
1 parent 20b1c6a commit 6a86361
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions yas3fs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
Expand All @@ -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):
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion yas3fs/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.2.0'
__version__ = '2.2.1'

0 comments on commit 6a86361

Please sign in to comment.