Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve download checksum checking #492

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions dropbox_uploader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -770,17 +770,17 @@ function db_download

#For each entry...
while read -r line; do

local FILE=${line%:*}
local META=${line##*:}
local TYPE=${META%;*}
local SIZE=${META#*;}
IFS=':;' read -r -a METADATA <<< "$line"
local FILE="${METADATA[0]}"
local TYPE="${METADATA[1]}"
local SIZE="${METADATA[2]}"
local HASH="${METADATA[3]}"

#Removing unneeded /
FILE=${FILE##*/}

if [[ $TYPE == "file" ]]; then
db_download_file "$SRC/$FILE" "$DEST_DIR/$FILE"
db_download_file "$SRC/$FILE" "$DEST_DIR/$FILE" "$HASH"
elif [[ $TYPE == "folder" ]]; then
db_download "$SRC/$FILE" "$DEST_DIR"
fi
Expand Down Expand Up @@ -819,6 +819,7 @@ function db_download_file
{
local FILE_SRC=$(normalize_path "$1")
local FILE_DST=$(normalize_path "$2")
local SRC_HASH=$3

if [[ $SHOW_PROGRESSBAR == 1 && $QUIET == 0 ]]; then
CURL_PARAMETERS="-L --progress-bar"
Expand All @@ -836,8 +837,11 @@ function db_download_file

# Checking if the file has the correct check sum
if [[ $TYPE != "ERR" ]]; then
sha_src=$(db_sha "$FILE_SRC")
sha_dst=$(db_sha_local "$FILE_DST")
local sha_src=$SRC_HASH
if [[ "$sha_src" == "" ]]; then
sha_src=$(db_sha "$FILE_SRC")
fi
local sha_dst=$(db_sha_local "$FILE_DST")
if [[ $sha_src == $sha_dst && $sha_src != "ERR" ]]; then
print "> Skipping file \"$FILE_SRC\", file exists with the same hash\n"
return
Expand Down Expand Up @@ -1138,8 +1142,9 @@ function db_list_outfile
local FILE=$(echo "$line" | sed -n 's/.*"path_display": *"\([^"]*\)".*/\1/p')
local TYPE=$(echo "$line" | sed -n 's/.*".tag": *"\([^"]*\).*/\1/p')
local SIZE=$(convert_bytes $(echo "$line" | sed -n 's/.*"size": *\([0-9]*\).*/\1/p'))
local HASH=$(echo "$line" | sed -n 's/.*"content_hash": *"\([^"]*\)".*/\1/p')

echo -e "$FILE:$TYPE;$SIZE" >> "$OUT_FILE"
echo -e "$FILE:$TYPE;$SIZE;$HASH" >> "$OUT_FILE"

done < "$TEMP_FILE"

Expand Down Expand Up @@ -1501,7 +1506,7 @@ function db_sha_local
done

shaHex=$(echo $SHA_CONCAT | sed 's/\([0-9A-F]\{2\}\)/\\x\1/gI')
echo -ne $shaHex | shasum -a 256 | awk '{print $1}'
echo -ne "$shaHex" | shasum -a 256 | awk '{print $1}'
}

################
Expand Down