Skip to content

Commit d7bf500

Browse files
committed
Fixed borked cache files on failed web requests
1 parent 31c2e02 commit d7bf500

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

compile.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ function download_file {
331331
echo "Cache hit for URL: $url" >> "$DIR/install.log"
332332
else
333333
echo "Downloading file to cache: $url" >> "$DIR/install.log"
334-
_download_file "$1" > "$DOWNLOAD_CACHE/$cached_filename" 2>> "$DIR/install.log"
334+
#download to a tmpfile first, so that we don't leave borked cache entries for later runs
335+
_download_file "$1" > "$DOWNLOAD_CACHE/.temp" 2>> "$DIR/install.log"
336+
mv "$DOWNLOAD_CACHE/.temp" "$DOWNLOAD_CACHE/$cached_filename" >> "$DIR/install.log" 2>&1
335337
fi
336338
cat "$DOWNLOAD_CACHE/$cached_filename" 2>> "$DIR/install.log"
337339
else

windows-compile-vs.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ function download-file {
227227
echo "Cache hit for URL: $url" >> $log_file
228228
} else {
229229
echo "Downloading file from $url to $cached_path" >> $log_file
230-
Invoke-WebRequest -Uri $url -OutFile $cached_path >> $log_file 2>&1
230+
#download to a tmpfile first, so that we don't leave borked cache entries for later runs
231+
Invoke-WebRequest -Uri $url -OutFile "$download_cache/.temp" >> $log_file 2>&1
232+
Move-Item "$download_cache/.temp" $cached_path >> $log_file 2>&1
231233
}
232234
if (!(Test-Path $cached_path)) {
233235
pm-fatal-error "Failed to download file from $url"

0 commit comments

Comments
 (0)