From 3855b9b657568f2270d63eae157923cc119fa866 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sat, 19 Aug 2023 14:47:30 +0300 Subject: Fixed bug for files less than 4097 bytes --- bin/ak-sm-merkle-tree | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/ak-sm-merkle-tree b/bin/ak-sm-merkle-tree index 60ad1ef..2ff6493 100755 --- a/bin/ak-sm-merkle-tree +++ b/bin/ak-sm-merkle-tree @@ -122,9 +122,14 @@ fi # We get the SHA512 hash for the $FILE given CHECKSUM=$(sha512sum "$FILE"|awk '{print $1}') - -# We split the file into 4*1024 bytes and output the chunks into TECHDIR -split -a 50 -b 4096 --additional-suffix ".chk" -d "$FILE" "$TECHDIR$(basename "$FILE")-" +FILE_SIZE="$(du -b $FILE | awk '{ print $1 }')" +if [ $FILE_SIZE -lt 4097 ] +then + cp $FILE "$TECHDIR$(basename "$FILE")-00000000000000000000000000000000000000000000000000.chk" +else + # We split the file into 4*1024 bytes and output the chunks into TECHDIR + split -a 50 -b 4096 --additional-suffix ".chk" -d "$FILE" "$TECHDIR$(basename "$FILE")-" +fi # We go over there... cd $TECHDIR @@ -172,9 +177,9 @@ do a=`expr "$a" + 2` done workingIndex="level.$c.map" + appendLastIfNotEven "$workingIndex" shaSum=`sha512sum $workingIndex | awk '{ print $1 }'` cp $workingIndex $MERKLEDIR/$shaSum - appendLastIfNotEven "$workingIndex" totalChunks=`cat $workingIndex | wc -l` c=`expr $c - 1` done -- cgit v1.2.3