@@ -146,7 +146,9 @@ def make_bag(bag_dir, bag_info=None, processes=1, checksum=None):
146146 bag_info ['Payload-Oxum' ] = Oxum
147147 _make_tag_file ('bag-info.txt' , bag_info )
148148
149- _make_tagmanifest_file ('tagmanifest-md5.txt' , bag_dir )
149+ for c in checksum :
150+ _make_tagmanifest_file (c , bag_dir )
151+
150152
151153 except Exception as e :
152154 os .chdir (old_dir )
@@ -311,7 +313,8 @@ def save(self, processes=1, manifests=False):
311313 _make_tag_file (self .tag_file_name , self .info )
312314
313315 # Update tag-manifest for changes to manifest & bag-info files
314- _make_tagmanifest_file ('tagmanifest-md5.txt' , self .path )
316+ for alg in self .algs :
317+ _make_tagmanifest_file (alg , self .path )
315318
316319 # Reload the manifests
317320 self ._load_manifests ()
@@ -759,14 +762,16 @@ def _make_manifest(manifest_file, data_dir, processes, algorithm='md5'):
759762 return "%s.%s" % (total_bytes , num_files )
760763
761764
762- def _make_tagmanifest_file (tagmanifest_file , bag_dir ):
765+ def _make_tagmanifest_file (alg , bag_dir ):
766+ tagmanifest_file = join (bag_dir , "tagmanifest-%s.txt" % alg )
767+ logging .info ("writing %s" , tagmanifest_file )
763768 files = [f for f in listdir (bag_dir ) if isfile (join (bag_dir , f ))]
764769 checksums = []
765770 for f in files :
766- if f == tagmanifest_file :
771+ if re . match ( '^tagmanifest-.+\.txt$' , f ) :
767772 continue
768773 fh = open (join (bag_dir , f ), 'rb' )
769- m = hashlib . md5 ( )
774+ m = _hasher ( alg )
770775 while True :
771776 bytes = fh .read (16384 )
772777 if not bytes :
@@ -830,8 +835,7 @@ def _manifest_line_sha256(filename):
830835def _manifest_line_sha512 (filename ):
831836 return _manifest_line (filename , 'sha512' )
832837
833- def _manifest_line (filename , algorithm = 'md5' ):
834- fh = open (filename , 'rb' )
838+ def _hasher (algorithm = 'md5' ):
835839 if algorithm == 'md5' :
836840 m = hashlib .md5 ()
837841 elif algorithm == 'sha1' :
@@ -840,6 +844,11 @@ def _manifest_line(filename, algorithm='md5'):
840844 m = hashlib .sha256 ()
841845 elif algorithm == 'sha512' :
842846 m = hashlib .sha512 ()
847+ return m
848+
849+ def _manifest_line (filename , algorithm = 'md5' ):
850+ fh = open (filename , 'rb' )
851+ m = _hasher (algorithm )
843852
844853 total_bytes = 0
845854 while True :
0 commit comments