hypriot/flash

Cache OS downloads?

Closed this issue · 5 comments

Love the http syntax, but does it download fresh every time? Could it use LastModified or ETAGs or some other http technique to avoid downloading the second time, and use local copy?

Great ideas. What flash does: It first tries to find the image file in /tmp where it gets extracted. See

flash/flash

Lines 495 to 500 in 58c68b0

if [ -f "/tmp/${filename}" ]; then
image=/tmp/${filename}
echo "Using cached image ${image}"
elif [ -f "/tmp/${filename}.img" ]; then
image=/tmp/${filename}.img
echo "Using cached image ${image}"

It's a "better than nothing" kind of cache without all these fancy stuff.
If we want to support cache better then new questions arise, who big should this cache be, ...

Shoot, I should have noticed that-- it sounds great, nothing more needed!

Actually, the /tmp cache doesn't seem to be working.

I just flashed a Pi successfully with sudo flash --force https://downloads.raspberrypi.org/raspbian_lite_latest

Inserted a new card, did it again, it downloaded the OS again instead of using /tmp.

Thoughts?

The simple cache doesn't work with download links that use a different name than the extracted img file. Look inside /tmp.
You can use that /tmp/xxxx name for further flashes or send me a PR to fix it :-)

Oh duh. I can use a more specific URL, the one above is likely a redirect. Thanks again.