X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fimport%2Fimport.c;h=af8d0ec42b27e1ad479d5f643ad52eb18103d8e4;hp=b4d859df1f408b538efaf99c8ae37ea625e59c0b;hb=edce2aed3aa93b84f7b4c70412bdb665da2977b0;hpb=5f129649b97bdff2bffefcd9c773157843ede6f6 diff --git a/src/import/import.c b/src/import/import.c index b4d859df1..af8d0ec42 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -45,10 +45,48 @@ static void on_raw_finished(RawImport *import, int error, void *userdata) { sd_event_exit(event, error); } +static int strip_raw_suffixes(const char *p, char **ret) { + static const char suffixes[] = + ".xz\0" + ".raw\0" + ".qcow2\0" + ".img\0"; + + _cleanup_free_ char *q = NULL; + + q = strdup(p); + if (!q) + return -ENOMEM; + + for (;;) { + const char *sfx; + bool changed = false; + + NULSTR_FOREACH(sfx, suffixes) { + char *e; + + e = endswith(q, sfx); + if (e) { + *e = 0; + changed = true; + } + } + + if (!changed) + break; + } + + *ret = q; + q = NULL; + + return 0; +} + static int pull_raw(int argc, char *argv[], void *userdata) { _cleanup_(raw_import_unrefp) RawImport *import = NULL; _cleanup_event_unref_ sd_event *event = NULL; - const char *url, *local, *suffix; + const char *url, *local; + _cleanup_free_ char *l = NULL; int r; url = argv[1]; @@ -79,9 +117,11 @@ static int pull_raw(int argc, char *argv[], void *userdata) { if (local) { const char *p; - suffix = endswith(local, ".raw"); - if (suffix) - local = strndupa(local, suffix - local); + r = strip_raw_suffixes(local, &l); + if (r < 0) + return log_oom(); + + local = l; if (!machine_name_is_valid(local)) { log_error("Local image name '%s' is not valid.", local);