aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Slaven <bpk@hoopajoo.net>2009-07-24 17:55:45 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2009-07-24 17:55:45 (GMT)
commit92fd67934ecfb5231e571340669b71e6ba62bfff (patch)
tree7307e4c45ca63079664b5d2133fbcf8f6122e0a1
parent742e6c310601882dbf1048ed2973ea38cbfc3575 (diff)
downloadfusearchive-92fd67934ecfb5231e571340669b71e6ba62bfff.zip
fusearchive-92fd67934ecfb5231e571340669b71e6ba62bfff.tar.gz
fusearchive-92fd67934ecfb5231e571340669b71e6ba62bfff.tar.bz2
Fix read bug on buffer boundry, make psyco a flag
-rwxr-xr-xfusearchive.py53
1 files changed, 40 insertions, 13 deletions
diff --git a/fusearchive.py b/fusearchive.py
index f009d3b..2db113e 100755
--- a/fusearchive.py
+++ b/fusearchive.py
@@ -26,6 +26,7 @@ fuse.feature_assert('stateful_files', 'has_init')
magic_profiling = False
enable_stats = False
+enable_psyco = False
debug_level = 0
# These control some of the file output
@@ -50,7 +51,10 @@ def save_chunk( chunk ):
if magic_profiling:
return( [ 0, 0 ] )
- dmsg( 2, "Begin save_chunk" )
+ dmsg( 2, "Begin save_chunk, length: " + str( len( chunk ) ) )
+ if debug_level > 4:
+ dmsg( 5, "Chunk: " + str( chunk ) )
+
# Save this hash string, similar to the backuppc algo
digest = sha.new( chunk ).digest()
@@ -136,14 +140,17 @@ def load_chunk( key ):
else:
raise IOError
+ if debug_level > 4:
+ dmsg( 5, "Load-Chunk: " + str( chunk ) )
+
return chunk
class FuseArchiveStream:
"""This just allows switching out writer classes easily"""
@staticmethod
def open( path, mode = 'r' ):
- return gzip.open( path, mode, gzip_compress_level )
- #return open( path, mode )
+ #return gzip.open( path, mode, gzip_compress_level )
+ return open( path, mode )
class FuseArchiveSerializer:
"""This lets us experiment with different main file serializers"""
@@ -400,6 +407,8 @@ class FuseArchive(Fuse):
dmsg( 3, "No chunk at this index, loading nothing" )
self.chunk = ''
+ dmsg( 3, "Loaded chunk of length: " + str( len( self.chunk ) ) )
+
self.chunk_index = index
self.chunk_modified = False
@@ -447,7 +456,7 @@ class FuseArchive(Fuse):
# Keep reading chunks until we have at least this much data
while data_read < length and not is_eof:
- dmsg( 3, "Pulling chunk data" )
+ dmsg( 3, "Pulling chunk data: " + str( index ) )
self._load_chunk( index )
if len(self.chunk):
chunk_remaining = len(self.chunk) - rest
@@ -456,9 +465,13 @@ class FuseArchive(Fuse):
if data_left < chunk_remaining:
to_read = data_left
+ dmsg( 3, "chunk_remaining: " + str( chunk_remaining ) )
+ dmsg( 3, "data_left: " + str( data_left ) )
+ dmsg( 3, "data_read: " + str( data_read ) )
+ dmsg( 3, "rest: " + str( rest ) )
dmsg( 3, "Copying " + str(to_read) + " bytes" )
- data += self.chunk[ rest:to_read ]
+ data += self.chunk[ rest:(rest+to_read) ]
data_read += to_read
index += 1
rest = 0
@@ -484,10 +497,14 @@ class FuseArchive(Fuse):
dmsg( 3, "Length: " + str( buf_len ) )
while( buf_offset < buf_len ):
- dmsg( 3, "Pulling in chunk for writing" )
+ dmsg( 3, "Pulling in chunk for writing: " + str(index) )
self._load_chunk( index )
buf_remain = buf_len - buf_offset
chunk_remain = self.chunk_size - rest
+
+ dmsg( 3, "buf_remain: " + str(buf_remain) )
+ dmsg( 3, "chunk_remain: " + str(chunk_remain) )
+
if chunk_remain < buf_remain:
dmsg( 3, "Writing " + str( chunk_remain ) + " bytes, buffer boundry" )
this_len = chunk_remain
@@ -499,6 +516,11 @@ class FuseArchive(Fuse):
dmsg( 3, " buf offset: " + str(buf_offset) )
dmsg( 3, " chunk offset: " + str(rest) )
+
+ if debug_level > 4:
+ dmsg( 5, "Pre-Buf: " + str(buf) )
+ dmsg( 5, "Pre-Chunk: " + str(self.chunk) )
+
# Since python doesn't do in-place reassignment like you
# can with splice() we will reconstruct the data by joining
# stuff by offsets (first chars to skip, then our joining
@@ -508,6 +530,10 @@ class FuseArchive(Fuse):
buf[ buf_offset:(buf_offset+this_len) ] + \
self.chunk[ (rest + this_len): ]
+ if debug_level > 4:
+ dmsg( 5, "Post-Buf: " + str(buf) )
+ dmsg( 5, "Post-Chunk: " + str(self.chunk) )
+
buf_offset += this_len
# Advance to next block
@@ -688,13 +714,14 @@ Userspace nullfs-alike: mirror the filesystem tree from some point on.
if __name__ == '__main__':
- # Import Psyco if available
- # doesn't seem to make a difference, must not be on this end
- #try:
- # import psyco
- # psyco.full()
- #except ImportError:
- # pass
+ if enable_psyco:
+ # Import Psyco if available
+ try:
+ import psyco
+ psyco.full()
+ except ImportError:
+ pass
+
if enable_stats:
import hotshot
prof = hotshot.Profile( "fusearchive_stats" )