Skip to content

Commit 6bf1009

Browse files
committed
fix: edge case bug when file size is 0 (file empty) - TODO: need to write a unit test
Signed-off-by: Stephen L. <LRQ3000@gmail.com>
1 parent 71129e6 commit 6bf1009

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

pyFileFixity/header_ecc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def main(argv=None, command=None):
468468
ptee.write("Precomputing done.")
469469
if generate: # show statistics only if generating an ecc file
470470
# TODO: add the size of the ecc format header? (arguments string + PYHEADERECC identifier)
471-
total_pred_percentage = sizeheaders * 100 / sizetotal
471+
total_pred_percentage = sizeheaders * 100 / max(1, sizetotal)
472472
ptee.write("Total ECC size estimation: %s = %g%% of total files size %s." % (sizeof_fmt(sizeheaders), total_pred_percentage, sizeof_fmt(sizetotal)))
473473
ptee.write("Details: resiliency of %i%%: For the header (first %i characters) of each file: each block of %i chars will get an ecc of %i chars (%i errors or %i erasures)." % (resilience_rate*100, header_size, ecc_params["message_size"], ecc_params["ecc_size"], int(ecc_params["ecc_size"] / 2), ecc_params["ecc_size"]))
474474

pyFileFixity/replication_repair.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def main(argv=None, command=None):
574574
# == Precomputation of ecc file size
575575
# Precomputing is important so that the user can know what size to expect before starting (and how much time it will take...).
576576
filescount = 0
577-
sizetotal = 0
577+
#sizetotal = 0 # TODO: unused
578578
sizeheaders = 0
579579
visitedfiles = {}
580580
ptee.write("Precomputing list of files and predicted statistics...")
@@ -591,10 +591,10 @@ def main(argv=None, command=None):
591591
filescount = filescount + 1
592592
# Add the file to the list of already visited files
593593
visitedfiles[relfilepath] = True
594-
# Get the current file's size
595-
size = os.stat(filepath).st_size
596-
# Compute total size of all files
597-
sizetotal = sizetotal + size
594+
# Get the current file's size # TODO: unused
595+
#size = os.stat(filepath).st_size
596+
# Compute total size of all files # TODO: unused
597+
#sizetotal = sizetotal + size
598598
prebar.update()
599599
prebar.close()
600600
ptee.write("Precomputing done.")

pyFileFixity/structural_adaptive_ecc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ def main(argv=None, command=None):
517517
ptee.write("Precomputing done.")
518518
if generate: # show statistics only if generating an ecc file
519519
# TODO: add the size of the ecc format header? (arguments string + PYHEADERECC identifier)
520+
#total_pred_percentage = sizeecc * 100 / max(1, sizetotal)
520521
total_pred_percentage = sizeecc * 100 / sizetotal
521522
ptee.write("Total ECC size estimation: %s = %g%% of total files size %s." % (sizeof_fmt(sizeecc), total_pred_percentage, sizeof_fmt(sizetotal)))
522523
ptee.write("Details per stage:")

0 commit comments

Comments
 (0)