summaryrefslogtreecommitdiff
path: root/src/import
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-01-17 02:36:23 +0100
committerLennart Poettering <lennart@poettering.net>2015-01-19 20:24:09 +0100
commitff6a74609b7c925834da1373d3adb9642ca51422 (patch)
tree23fc620efd4a35c0d2d138a1d887d6c8465253ff /src/import
parent47bc4fd86d1119945be3d0217f3795c901b7ffff (diff)
import-raw: when downloading raw images, generate sparse files if we can
Diffstat (limited to 'src/import')
-rw-r--r--src/import/import-raw.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index f830ba47ff..c82d263787 100644
--- a/src/import/import-raw.c
+++ b/src/import/import-raw.c
@@ -332,6 +332,14 @@ static void raw_import_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result
goto fail;
}
+ /* Make sure the file size is right, in case the file was
+ * sparse and we just seeked for the last part */
+ if (ftruncate(f->disk_fd, f->written_uncompressed) < 0) {
+ log_error_errno(errno, "Failed to truncate file: %m");
+ r = -errno;
+ goto fail;
+ }
+
r = raw_import_maybe_convert_qcow2(f);
if (r < 0)
goto fail;
@@ -427,7 +435,7 @@ static int raw_import_file_write_uncompressed(RawImportFile *f, void *p, size_t
return -EFBIG;
}
- n = write(f->disk_fd, p, sz);
+ n = sparse_write(f->disk_fd, p, sz, 64);
if (n < 0) {
log_error_errno(errno, "Failed to write file: %m");
return -errno;