@@ -146,7 +146,9 @@ def make_bag(bag_dir, bag_info=None, processes=1, checksum=None):
146
146
bag_info ['Payload-Oxum' ] = Oxum
147
147
_make_tag_file ('bag-info.txt' , bag_info )
148
148
149
- _make_tagmanifest_file ('tagmanifest-md5.txt' , bag_dir )
149
+ for c in checksum :
150
+ _make_tagmanifest_file (c , bag_dir )
151
+
150
152
151
153
except Exception as e :
152
154
os .chdir (old_dir )
@@ -311,7 +313,8 @@ def save(self, processes=1, manifests=False):
311
313
_make_tag_file (self .tag_file_name , self .info )
312
314
313
315
# 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 )
315
318
316
319
# Reload the manifests
317
320
self ._load_manifests ()
@@ -759,14 +762,16 @@ def _make_manifest(manifest_file, data_dir, processes, algorithm='md5'):
759
762
return "%s.%s" % (total_bytes , num_files )
760
763
761
764
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 )
763
768
files = [f for f in listdir (bag_dir ) if isfile (join (bag_dir , f ))]
764
769
checksums = []
765
770
for f in files :
766
- if f == tagmanifest_file :
771
+ if re . match ( '^tagmanifest-.+\.txt$' , f ) :
767
772
continue
768
773
fh = open (join (bag_dir , f ), 'rb' )
769
- m = hashlib . md5 ( )
774
+ m = _hasher ( alg )
770
775
while True :
771
776
bytes = fh .read (16384 )
772
777
if not bytes :
@@ -830,8 +835,7 @@ def _manifest_line_sha256(filename):
830
835
def _manifest_line_sha512 (filename ):
831
836
return _manifest_line (filename , 'sha512' )
832
837
833
- def _manifest_line (filename , algorithm = 'md5' ):
834
- fh = open (filename , 'rb' )
838
+ def _hasher (algorithm = 'md5' ):
835
839
if algorithm == 'md5' :
836
840
m = hashlib .md5 ()
837
841
elif algorithm == 'sha1' :
@@ -840,6 +844,11 @@ def _manifest_line(filename, algorithm='md5'):
840
844
m = hashlib .sha256 ()
841
845
elif algorithm == 'sha512' :
842
846
m = hashlib .sha512 ()
847
+ return m
848
+
849
+ def _manifest_line (filename , algorithm = 'md5' ):
850
+ fh = open (filename , 'rb' )
851
+ m = _hasher (algorithm )
843
852
844
853
total_bytes = 0
845
854
while True :
0 commit comments