From 4873d2d77451c0b5846b2f129c7abf92f10e4d7d Mon Sep 17 00:00:00 2001 From: Steve Slaven Date: Thu, 23 Jul 2009 15:02:37 -0700 Subject: Fixed getattr to use fgetattr so we don't have to maintain 2 functions diff --git a/fusearchive.py b/fusearchive.py index f97911b..810e05f 100755 --- a/fusearchive.py +++ b/fusearchive.py @@ -26,7 +26,7 @@ fuse.feature_assert('stateful_files', 'has_init') magic_blocksize = 1024 * 32 magic_depth = 5 -debug_level = 4 +debug_level = 1 def dmsg(level,message): if level <= debug_level: @@ -151,21 +151,16 @@ class FuseArchive(Fuse): # Fix getattr and fgetattr to? def getattr(self, path): treefile = "./tree" + path - stats = os.lstat( treefile ) if os.path.isfile( treefile ): - dmsg( 3, "Reading file to get size: " + path ) + dmsg( 3, "Delegating getattr to FuserArchiveFile" ) - #pdb.set_trace() - - # Override size - inp = gzip.open( treefile ) - magic = pickle.load( inp ) - inp.close() - - dmsg( 3, "Overridding getattr" ) - stats = FuseArchiveStat( stats ) - stats.overstat( magic[ 'size' ] ) + f = self.FuseArchiveFile( path, os.O_RDONLY, 0 ) + stats = f.fgetattr() + f.release( 0 ) + else: + dmsg( 3, "Using os.lstat to get stats" ) + stats = os.lstat( treefile ) return stats @@ -493,8 +488,17 @@ class FuseArchive(Fuse): self._fflush() def fgetattr(self): - print "WARNING: fgetattr is broken!!!!" - return os.lstat( "./tree" + self.orig_path ) + dmsg( 3, "Overridding fgetattr" ) + stats = FuseArchiveStat( os.lstat( "./tree" + self.orig_path ) ) + + if self.modified: + # We would need to fsync here to recalc size, but don't do + # it unless modified? otherwise simple getattr will be + # rewriting a ton of files + print "WARNING: self.modified causes fgetattr to be incorrect!" + + stats.overstat( self.size ) + return stats def ftruncate(self, len): if len > 0: -- cgit v0.10.2