diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-12-26 17:10:31 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-12-26 19:21:58 +0100 |
commit | 8620a9a32391fd74d70ddc07c9b79729ad4ec067 (patch) | |
tree | 0e541a952c8d0f232605a21194540eed06afb307 /src/import/import.c | |
parent | e9d7333468ff02fd45a8aeb957e758f641026278 (diff) |
import: beef up gpt importer to optionally make writable copy of read-only vendor image
Diffstat (limited to 'src/import/import.c')
-rw-r--r-- | src/import/import.c | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/src/import/import.c b/src/import/import.c index a81200c9ff..79dd203142 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -47,22 +47,18 @@ static void on_gpt_finished(GptImport *import, int error, void *userdata) { static int pull_gpt(int argc, char *argv[], void *userdata) { _cleanup_(gpt_import_unrefp) GptImport *import = NULL; _cleanup_event_unref_ sd_event *event = NULL; - _cleanup_free_ char *local_truncated = NULL, *local_generated = NULL; const char *url, *local, *suffix; int r; url = argv[1]; - local = argv[2]; - if (!gpt_url_is_valid(url)) { log_error("URL '%s' is not valid.", url); return -EINVAL; } - if (isempty(local) || streq(local, "-")) - local = NULL; - - if (!local) { + if (argc >= 3) + local = argv[2]; + else { const char *e, *p; e = url + strlen(url); @@ -73,28 +69,36 @@ static int pull_gpt(int argc, char *argv[], void *userdata) { while (p > url && p[-1] != '/') p--; - local_generated = strndup(p, e - p); - if (!local_generated) - return log_oom(); - - local = local_generated; + local = strndupa(p, e - p); } - suffix = endswith(local, ".gpt"); - if (suffix) { - local_truncated = strndup(local, suffix - local); - if (!local_truncated) - return log_oom(); + if (isempty(local) || streq(local, "-")) + local = NULL; - local = local_truncated; - } + if (local) { + const char *p; - if (!machine_name_is_valid(local)) { - log_error("Local image name '%s' is not valid.", local); - return -EINVAL; - } + suffix = endswith(local, ".gpt"); + if (suffix) + local = strndupa(local, suffix - local); - log_info("Pulling '%s' as '%s'", url, local); + if (!machine_name_is_valid(local)) { + log_error("Local image name '%s' is not valid.", local); + return -EINVAL; + } + + p = strappenda("/var/lib/container/", local, ".gpt"); + if (laccess(p, F_OK) >= 0) { + if (!arg_force) { + log_info("Image '%s' already exists.", local); + return 0; + } + } else if (errno != ENOENT) + return log_error_errno(errno, "Can't check if image '%s' already exists: %m", local); + + log_info("Pulling '%s', saving as '%s'.", url, local); + } else + log_info("Pulling '%s'.", url); r = sd_event_default(&event); if (r < 0) @@ -153,6 +157,16 @@ static int pull_dkr(int argc, char *argv[], void *userdata) { tag = "latest"; } + if (!dkr_name_is_valid(name)) { + log_error("Remote name '%s' is not valid.", name); + return -EINVAL; + } + + if (!dkr_tag_is_valid(tag)) { + log_error("Tag name '%s' is not valid.", tag); + return -EINVAL; + } + if (argc >= 3) local = argv[2]; else { @@ -166,16 +180,6 @@ static int pull_dkr(int argc, char *argv[], void *userdata) { if (isempty(local) || streq(local, "-")) local = NULL; - if (!dkr_name_is_valid(name)) { - log_error("Remote name '%s' is not valid.", name); - return -EINVAL; - } - - if (!dkr_tag_is_valid(tag)) { - log_error("Tag name '%s' is not valid.", tag); - return -EINVAL; - } - if (local) { const char *p; |