diff options
Diffstat (limited to 'FuseArchive/ChunkFile.py')
-rw-r--r-- | FuseArchive/ChunkFile.py | 13 |
1 files changed, 13 insertions, 0 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 ) |