@@ -396,6 +396,42 @@ def func(data):
396396 return bytesread , sum .hexdigest ()
397397
398398
399+ def recover_repofiles (options , repofiles , outfp ):
400+ if options .withverify :
401+ datfile = os .path .splitext (repofiles [0 ])[0 ] + '.dat'
402+ with open (datfile ) as fp :
403+ truth_dict = {}
404+ for line in fp :
405+ fn , startpos , endpos , sum = line .split ()
406+ startpos = int (startpos )
407+ endpos = int (endpos )
408+ filename = os .path .join (options .repository ,
409+ os .path .basename (fn ))
410+ truth_dict [filename ] = {
411+ 'size' : endpos - startpos ,
412+ 'sum' : sum ,
413+ }
414+ totalsz = 0
415+ for repofile in repofiles :
416+ reposz , reposum = concat ([repofile ], outfp )
417+ expected_truth = truth_dict [repofile ]
418+ if reposz != expected_truth ['size' ]:
419+ raise VerificationFail (
420+ "%s is %d bytes, should be %d bytes" % (
421+ repofile , reposz , expected_truth ['size' ]))
422+ if reposum != expected_truth ['sum' ]:
423+ raise VerificationFail (
424+ "{} has checksum {} instead of {}" .format (
425+ repofile , reposum , expected_truth ['sum' ]))
426+ totalsz += reposz
427+ log ("Recovered chunk %s : %s bytes, md5: %s" ,
428+ repofile , reposz , reposum )
429+ log ("Recovered a total of %s bytes" , totalsz )
430+ else :
431+ reposz , reposum = concat (repofiles , outfp )
432+ log ('Recovered %s bytes, md5: %s' , reposz , reposum )
433+
434+
399435def gen_filedate (options ):
400436 return getattr (options , 'test_now' , time .gmtime ()[:6 ])
401437
@@ -698,40 +734,7 @@ def do_recover(options):
698734 files_to_close += (outfp ,)
699735
700736 try :
701- if options .withverify :
702- datfile = os .path .splitext (repofiles [0 ])[0 ] + '.dat'
703- with open (datfile ) as fp :
704- truth_dict = {}
705- for line in fp :
706- fn , startpos , endpos , sum = line .split ()
707- startpos = int (startpos )
708- endpos = int (endpos )
709- filename = os .path .join (options .repository ,
710- os .path .basename (fn ))
711- truth_dict [filename ] = {
712- 'size' : endpos - startpos ,
713- 'sum' : sum ,
714- }
715- totalsz = 0
716- for repofile in repofiles :
717- reposz , reposum = concat ([repofile ], outfp )
718- expected_truth = truth_dict [repofile ]
719- if reposz != expected_truth ['size' ]:
720- raise VerificationFail (
721- "%s is %d bytes, should be %d bytes" % (
722- repofile , reposz , expected_truth ['size' ]))
723- if reposum != expected_truth ['sum' ]:
724- raise VerificationFail (
725- "{} has checksum {} instead of {}" .format (
726- repofile , reposum , expected_truth ['sum' ]))
727- totalsz += reposz
728- log ("Recovered chunk %s : %s bytes, md5: %s" ,
729- repofile , reposz , reposum )
730- log ("Recovered a total of %s bytes" , totalsz )
731- else :
732- reposz , reposum = concat (repofiles , outfp )
733- log ('Recovered %s bytes, md5: %s' , reposz , reposum )
734-
737+ recover_repofiles (options , repofiles , outfp )
735738 if options .output is not None :
736739 last_base = os .path .splitext (repofiles [- 1 ])[0 ]
737740 source_index = '%s.index' % last_base
0 commit comments