Author: poeml Date: Tue Sep 8 20:15:35 2009 New Revision: 7793 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=7793&view=rev Log: metalink-hasher: - "copy" the modification time to the hash file, in preparation to make Apache check if it's identical (until now, it checked only if it's newer) - revert the recent change looking at the inode to judge whether files have changed, and instead use the file size (in combination with the mtime, just as rsync does). Migrate existing hashes, so that the files don't need to be hashed again (which could be very time-consuming). - ignore if a file that is supposed to be unlinked doesn't exist, which occurs for instance in the above mentioned scenario, where the hash files are renamed to a different name. Modified: trunk/tools/metalink-hasher.py Modified: trunk/tools/metalink-hasher.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/tools/metalink-hasher.py?rev=7793&r1=7792&r2=7793&view=diff ============================================================================== --- trunk/tools/metalink-hasher.py (original) +++ trunk/tools/metalink-hasher.py Tue Sep 8 20:15:35 2009 @@ -54,6 +54,7 @@ self.src = os.path.join(src_dir, self.basename) self.finfo = os.lstat(self.src) + self.atime = self.finfo.st_atime self.mtime = self.finfo.st_mtime self.size = self.finfo.st_size self.inode = self.finfo.st_ino @@ -61,8 +62,12 @@ self.dst_dir = dst_dir - self.dst_basename = '%s.inode_%s' % (self.basename, self.inode) + self.dst_basename = '%s.size_%s' % (self.basename, self.size) self.dst = os.path.join(self.dst_dir, self.dst_basename) + + # migration 2.10.0 -> 2.10.1 + self.dst_old_basename = '%s.inode_%s' % (self.basename, self.inode) + self.dst_old = os.path.join(self.dst_dir, self.dst_old_basename) def islink(self): return stat.S_ISLNK(self.mode) @@ -79,9 +84,17 @@ except OSError: dst_mtime = dst_size = 0 # file missing - if dst_mtime >= self.mtime and dst_size != 0: + if dst_mtime == self.mtime and dst_size != 0: if verbose: print 'Up to date: %r' % self.dst + return + + if os.path.exists(self.dst_old): + # upgrade mode 2.10.0 -> 2.10.1 + print 'migrating %s -> %s' % (self.dst_old, self.dst) + if not dry_run: + os.rename(self.dst_old, self.dst) + os.utime(self.dst, (self.atime, self.mtime)) return cmd = [ 'metalink', @@ -118,6 +131,8 @@ d = open(self.dst, 'wb') d.write(''.join(lines)) d.close() + + os.utime(self.dst, (self.atime, self.mtime)) if copy_permissions: os.chmod(self.dst, self.mode) @@ -312,8 +327,9 @@ try: os.unlink(i_path) except OSError, e: - sys.stderr.write('Unlink failed for %r: %s\n' \ - % (i_path, os.strerror(e.errno))) + if e.errno != errno.ENOENT: + sys.stderr.write('Unlink failed for %r: %s\n' \ + % (i_path, os.strerror(e.errno))) unlinked_files += 1 _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Tue Sep 08 2009 - 18:15:38 GMT
This archive was generated by hypermail 2.2.0 : Tue Sep 08 2009 - 18:45:06 GMT