Skip to content

Commit

Permalink
fix remote vs local file comparison in bash script (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuliiaKovalova committed Sep 18, 2023
1 parent 0d90292 commit e9163da
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/dotnet-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ validate_remote_local_file_sizes()

local downloaded_file="$1"
local remote_file_size="$2"

local file_size=''

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
file_size="$(stat -c '%s' "$downloaded_file")"
elif [[ "$OSTYPE" == "darwin"* ]]; then
Expand All @@ -575,8 +575,8 @@ validate_remote_local_file_sizes()
say "Downloaded file size is $file_size bytes."

if [ -n "$remote_file_size" ] && [ -n "$file_size" ]; then
if [ "$file_size" != "$remote_file_size" ]; then
say "The remote and local file sizes are not equal. Remote file size is $remote_file_size bytes and local size is $file_size bytes. The local package may be corrupted."
if [ "$remote_file_size" -ne "$file_size" ]; then
say "The remote and local file sizes are not equal. The remote file size is $remote_file_size bytes and the local size is $file_size bytes. The local package may be corrupted."
else
say "The remote and local file sizes are equal."
fi
Expand Down Expand Up @@ -961,9 +961,9 @@ get_remote_file_size() {
local zip_uri="$1"
if machine_has "curl"; then
file_size=$(curl -sI "$zip_uri" | grep -i content-length | awk '{print $2}')
file_size=$(curl -sI "$zip_uri" | grep -i content-length | awk '{ num = $2 + 0; print num }')
elif machine_has "wget"; then
file_size=$(wget --server-response -O /dev/null "$zip_uri" 2>&1 | grep -i '^Content-Length:' | awk '{print $2}')
file_size=$(wget --spider --server-response -O /dev/null "$zip_uri" 2>&1 | grep -i 'Content-Length:' | awk '{ num = $2 + 0; print num }')
else
say "Neither curl nor wget is available on this system."
return
Expand Down Expand Up @@ -1497,7 +1497,7 @@ install_dotnet() {
eval $invocation
local download_failed=false
local download_completed=false
local remote_file_size=''
local remote_file_size=0
mkdir -p "$install_root"
zip_path="${zip_path:-$(mktemp "$temporary_file_template")}"
Expand Down Expand Up @@ -1826,4 +1826,4 @@ fi
say "Note that the script does not resolve dependencies during installation."
say "To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the \"Dependencies\" section."
say "Installation finished successfully."
say "Installation finished successfully."

0 comments on commit e9163da

Please sign in to comment.