chiark / gitweb /
import: add support for pulling raw tar balls as containers
[elogind.git] / src / import / import-raw.c
index 361e30ac83126fcb802a3b1964afa35e362d077d..1fe27b6932025bf9f10b3cfe1c9ada67061097d5 100644 (file)
 #include "utf8.h"
 #include "curl-util.h"
 #include "qcow2-util.h"
-#include "import-raw.h"
 #include "strv.h"
 #include "copy.h"
+#include "import-util.h"
+#include "import-raw.h"
 
 typedef struct RawImportFile RawImportFile;
 
@@ -104,6 +105,7 @@ static RawImportFile *raw_import_file_unref(RawImportFile *f) {
                 free(f->temp_path);
         }
 
+        lzma_end(&f->lzma);
         free(f->url);
         free(f->local);
         free(f->etag);
@@ -263,6 +265,8 @@ static int raw_import_maybe_convert_qcow2(RawImportFile *f) {
         if (converted_fd < 0)
                 return log_error_errno(errno, "Failed to create %s: %m", t);
 
+        log_info("Unpacking QCOW2 file.");
+
         r = qcow2_convert(f->disk_fd, converted_fd);
         if (r < 0) {
                 unlink(t);
@@ -688,17 +692,6 @@ static int raw_import_file_progress_callback(void *userdata, curl_off_t dltotal,
         return 0;
 }
 
-static bool etag_is_valid(const char *etag) {
-
-        if (!endswith(etag, "\""))
-                return false;
-
-        if (!startswith(etag, "\"") && !startswith(etag, "W/\""))
-                return false;
-
-        return true;
-}
-
 static int raw_import_file_find_old_etags(RawImportFile *f) {
         _cleanup_free_ char *escaped_url = NULL;
         _cleanup_closedir_ DIR *d = NULL;
@@ -748,7 +741,7 @@ static int raw_import_file_find_old_etags(RawImportFile *f) {
                 if (!u)
                         return -ENOMEM;
 
-                if (!etag_is_valid(u)) {
+                if (!http_etag_is_valid(u)) {
                         free(u);
                         continue;
                 }
@@ -901,7 +894,7 @@ int raw_import_pull(RawImport *import, const char *url, const char *local, bool
         int r;
 
         assert(import);
-        assert(raw_url_is_valid(url));
+        assert(http_url_is_valid(url));
         assert(!local || machine_name_is_valid(local));
 
         if (hashmap_get(import->files, url))
@@ -946,14 +939,3 @@ int raw_import_pull(RawImport *import, const char *url, const char *local, bool
         f = NULL;
         return 0;
 }
-
-bool raw_url_is_valid(const char *url) {
-        if (isempty(url))
-                return false;
-
-        if (!startswith(url, "http://") &&
-            !startswith(url, "https://"))
-                return false;
-
-        return ascii_is_valid(url);
-}