diff options
Diffstat (limited to 'FuseArchive/ChunkFile.py')
-rw-r--r-- | FuseArchive/ChunkFile.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/FuseArchive/ChunkFile.py b/FuseArchive/ChunkFile.py index 051965f..ac39439 100644 --- a/FuseArchive/ChunkFile.py +++ b/FuseArchive/ChunkFile.py @@ -1,4 +1,4 @@ -import logging, os, errno, fcntl, fuse, FuseArchive +import logging, os, errno, fcntl, fuse, FuseArchive, copy import FuseArchive.Storage.ZipFile, FuseArchive.Storage.FileSystem from binascii import hexlify from FuseArchive.Serializer import Serializer @@ -34,7 +34,10 @@ def flag2mode(flags): if chunkstyle == 'fs': load_chunk = FuseArchive.Storage.FileSystem.load_chunk save_chunk = FuseArchive.Storage.FileSystem.save_chunk + lock_chunk = FuseArchive.Storage.FileSystem.lock_chunk + unlock_chunk = FuseArchive.Storage.FileSystem.unlock_chunk elif chunkstyle == 'zip': + raise ValueException( "Zip storage doesn't support lock/unlock, make an inteface!" ) load_chunk = FuseArchive.Storage.ZipFile.load_chunk save_chunk = FuseArchive.Storage.ZipFile.save_chunk else: @@ -136,6 +139,7 @@ class ChunkFile(object): self.direct_io = False self.keep_cache = False + self.original_chunks = copy.deepcopy( self.chunks ) logging.debug( "%s init complete" % self ) @@ -210,6 +214,29 @@ class ChunkFile(object): logging.debug( "Key was %s" % key ) self.dirty_chunks = 0 + # Is this chunk changed from what was here before? + oldkey = None + key = self.chunks[ index ] + + changed = False + # Is the old chunks at least this big? + if index >= len( self.original_chunks ): + logging.debug( "No old chunk at this spot, changed for sure" ) + changed = True + else: + oldkey = self.original_chunks[ index ] + if oldkey != key: + logging.debug( "Key has changed at index %d" % index ) + changed = True + logging.debug( "%s is now %s" % (oldkey, key) ) + + if changed: + logging.debug( "Chunk at index %d has changed" % index ) + if oldkey != None: + unlock_chunk( oldkey ) + + lock_chunk( key ) + def read(self, length, offset): logging.debug( "Reading from %s offset: %d (0x%x) length: %d (0x%d)" % ( self.orig_path, offset, offset, length, length ) ) |