import: Only keep RO copy if ETag header is set
authorKevin Kuehler <keur@xcf.berkeley.edu>
Sun, 15 Mar 2020 20:46:27 +0000 (13:46 -0700)
committerKevin Kuehler <keur@xcf.berkeley.edu>
Tue, 24 Mar 2020 04:39:59 +0000 (21:39 -0700)
commit50dfca2eaf325835c2bd75565f65bfbe84d3cae5
tree576d62939418c5918d94588cbc17e66c63767ea6
parent992622c4289ef7c956a7bfef5eb8e5ab93e43457
import: Only keep RO copy if ETag header is set

We fix the case when the webserver servers container images without
setting the ETag header in the response.  When an image is downloaded to
image root, a read only copy is stored alongside it.  The filename has
the following form:
    .raw-<encoded-url-of-image>.\x22<ETAG-header>\22.raw.
This is so, if the same resource is fetched multiple times, importd can
avoid extra downloads by creating the new image using the local read-only copy.

The current code assumes the ETag header is set because, if the server
does not set the ETag header, the file is stored without the ETag value
in the filename. When importd fetches a duplicate image, it will run
rename_noreplace and fail:

  Failed to rename raw file to /var/lib/machines/.raw-http:\x2f\x2flocalhost:8000\x2fwalkthroughd.raw: File exists

This patch makes importd only store a read-only image if the webserver
has set the ETag header.
src/import/pull-raw.c