+
+ # Copy provided OTS if matching OTS found stored but provided is older
+ if [[ "$blk_provid" -lt "$blk_stored" ]]; then
+ vbm "WARNING:Provided OTS file somehow older despite having same name. Previous error in storing OTS file?";
+ must mv "$pout" "${pout}--$(date +%s)";
+ must cp "$fin" "$pout";
+ return 0;
+ else
+ vbm "STATUS:Stored OTS file has block number older than or as old as provided OTS file.";
+ fi;
+}; # Stores provided OTS file is none already stored
+get_sha256_digest() {
+ # Depends: GNU Coreutils 8.32 (sha256sum)
+ # Input: arg1 path file path
+ # Output: stdout str sha256 digest (lowercase hexadecimal)
+ vbm "DEBUG:Starting get_sha256_digest()";
+ sha256sum "$1" | head -n1 | sed -E -e 's/(^[0-9a-f]{64})(.+)/\1/';
+};
+get_oldest_stored_ots_path() {
+ # Desc: Lookup most recent OTS file from storage
+ # Input: pathOtsStore var path to OTS storage dir
+ # arg1 str sha256 digest (lowercase hexadecimal)
+ # Output: stdout path OTS file with matching sha256 digest
+ vbm "DEBUG:Starting get_oldest_stored_ots_path()";
+ local -a otsStorePaths;
+ local i_oldest;
+
+ digest="$1";
+ mapfile -t otsStorePaths < <(find "$pathOtsStore" -type f -name "${digest}*.otsu"; );
+ if [[ "${#otsStorePaths[@]}" -le 0 ]]; then
+ yell "ERROR:No OTS file in OTS storage dir found. $(declare -p pathOtsStore digest otsStorePaths)";
+ return 1;
+ fi;
+ i_oldest=0;
+ blockNumOldest="$( get_block_num_from_stored_ots_path "${otsStorePaths[0]}" )";
+ for ((i=0; i<"${#otsStorePaths[@]}"; i++ )); do
+ blockNum="$( get_block_num_from_stored_ots_path "${otsStorePaths[$i]}" )";
+ if [[ $blockNum -lt $blockNumOldest ]]; then
+ blockNumOldest=$blockNum;
+ i_oldest=$i;
+ fi;
+ done;
+ output="$(readlink -f "${otsStorePaths[$i_oldest]}"; )";