From 44db0f423142b3757cd08f77562ee29c6575aa2a Mon Sep 17 00:00:00 2001 From: Steve Slaven Date: Thu, 6 Aug 2009 16:45:45 -0700 Subject: 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 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) -- cgit v0.10.2