aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Slaven <bpk@hoopajoo.net>2009-08-06 23:45:45 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2009-08-06 23:45:45 (GMT)
commit44db0f423142b3757cd08f77562ee29c6575aa2a (patch)
treeabbb09c732acecc2d6a68d0fe7a8c94915df1177
parent7f8c15ebab3a2ebe8d2929f1b3e5abb160866b57 (diff)
downloadfusearchive-44db0f423142b3757cd08f77562ee29c6575aa2a.zip
fusearchive-44db0f423142b3757cd08f77562ee29c6575aa2a.tar.gz
fusearchive-44db0f423142b3757cd08f77562ee29c6575aa2a.tar.bz2
Pre-init original_chunks because we might need to fflush early in the
constructor, use ftruncate since truncate doesn't exist, and handle unlocking unused chunks due to ftruncate
-rw-r--r--FuseArchive/ChunkFile.py13
-rw-r--r--FuseArchive/FileSystem.py2
2 files changed, 14 insertions, 1 deletions
diff --git a/FuseArchive/ChunkFile.py b/FuseArchive/ChunkFile.py
index 5432f3b..e713e10 100644
--- a/FuseArchive/ChunkFile.py
+++ b/FuseArchive/ChunkFile.py
@@ -87,6 +87,11 @@ class ChunkFile(object):
# The chunk table
self.chunks = []
+ # Because python is bizarre and you magically define attributes in
+ # the constructor we predefine this here for the case where we
+ # fflush early if we're creating a new file since we reference this
+ # attribute in the routine. At least it gets initialized I guess
+ self.original_chunks = []
# TODO: Better flag handling here?
if flags & os.O_RDONLY:
@@ -427,6 +432,14 @@ class ChunkFile(object):
lock_chunk( key )
+ # Free any unused chunks because of ftruncate
+ logging.debug( "Freeing chunks beyond our new chunk count" )
+ index = len( self.chunks )
+ while index < len( self.original_chunks ):
+ logging.debug( "Unlocking chunk at index %d" % index )
+ unlock_chunk( self.original_chunks[ index ] )
+ index += 1
+
# Update our original_chunks since we've locked/unlocked some
# things
self.original_chunks = copy.deepcopy( self.chunks )
diff --git a/FuseArchive/FileSystem.py b/FuseArchive/FileSystem.py
index e70bba6..16e5b2c 100644
--- a/FuseArchive/FileSystem.py
+++ b/FuseArchive/FileSystem.py
@@ -49,7 +49,7 @@ class FileSystem(fuse.Fuse):
def unlink(self, path):
# Do a truncate to free our chunks
f = ChunkFile( path, os.O_RDWR, 0 )
- f.truncate( 0 )
+ f.ftruncate( 0 )
f.release( 0 )
os.unlink("./tree" + path)