mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
Merge pull request #20500 from poettering/import-tweaks
a few minor tweaks/bugfixlets to importd backends
This commit is contained in:
commit
218262c0b1
@ -256,6 +256,9 @@ int curl_glue_make(CURL **ret, const char *url, void *userdata) {
|
||||
if (curl_easy_setopt(c, CURLOPT_LOW_SPEED_LIMIT, 30L) != CURLE_OK)
|
||||
return -EIO;
|
||||
|
||||
if (curl_easy_setopt(c, CURLOPT_PROTOCOLS, CURLPROTO_HTTP|CURLPROTO_HTTPS|CURLPROTO_FILE) != CURLE_OK)
|
||||
return -EIO;
|
||||
|
||||
*ret = TAKE_PTR(c);
|
||||
return 0;
|
||||
}
|
||||
|
@ -185,10 +185,11 @@ static int import_fs(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
(void) mkdir_parents_label(temp_path, 0700);
|
||||
dest = temp_path;
|
||||
}
|
||||
|
||||
(void) mkdir_parents_label(dest, 0700);
|
||||
|
||||
progress.limit = (RateLimit) { 200*USEC_PER_MSEC, 1 };
|
||||
|
||||
{
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "btrfs-util.h"
|
||||
#include "copy.h"
|
||||
#include "fd-util.h"
|
||||
#include "format-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "hostname-util.h"
|
||||
#include "import-common.h"
|
||||
@ -248,6 +249,8 @@ static int raw_import_finish(RawImport *i) {
|
||||
|
||||
i->temp_path = mfree(i->temp_path);
|
||||
|
||||
log_info("Wrote %s.", FORMAT_BYTES(i->written_uncompressed));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -319,6 +322,9 @@ static int raw_import_try_reflink(RawImport *i) {
|
||||
if (i->compress.type != IMPORT_COMPRESS_UNCOMPRESSED)
|
||||
return 0;
|
||||
|
||||
if (i->offset != UINT64_MAX || i->size_max != UINT64_MAX)
|
||||
return 0;
|
||||
|
||||
if (!S_ISREG(i->input_stat.st_mode) || !S_ISREG(i->output_stat.st_mode))
|
||||
return 0;
|
||||
|
||||
@ -365,7 +371,7 @@ static int raw_import_write(const void *p, size_t sz, void *userdata) {
|
||||
}
|
||||
|
||||
/* Generate sparse file if we created/truncated the file */
|
||||
if (S_ISREG(i->output_stat.st_mode)) {
|
||||
if (S_ISREG(i->output_stat.st_mode) && i->offset == UINT64_MAX) {
|
||||
ssize_t n;
|
||||
|
||||
n = sparse_write(i->output_fd, p, sz, 64);
|
||||
|
@ -928,7 +928,7 @@ static int method_pull_tar_or_raw(sd_bus_message *msg, void *userdata, sd_bus_er
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!http_url_is_valid(remote))
|
||||
if (!http_url_is_valid(remote) && !file_url_is_valid(remote))
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
||||
"URL %s is invalid", remote);
|
||||
|
||||
|
@ -117,7 +117,7 @@ static int pull_job_restart(PullJob *j, const char *new_url) {
|
||||
void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result) {
|
||||
PullJob *j = NULL;
|
||||
CURLcode code;
|
||||
long status;
|
||||
long protocol;
|
||||
int r;
|
||||
|
||||
if (curl_easy_getinfo(curl, CURLINFO_PRIVATE, (char **)&j) != CURLE_OK)
|
||||
@ -131,50 +131,62 @@ void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
|
||||
code = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
|
||||
if (code != CURLE_OK) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to retrieve response code: %s", curl_easy_strerror(code));
|
||||
goto finish;
|
||||
} else if (status == 304) {
|
||||
log_info("Image already downloaded. Skipping download.");
|
||||
j->etag_exists = true;
|
||||
r = 0;
|
||||
goto finish;
|
||||
} else if (status >= 300) {
|
||||
}
|
||||
|
||||
if (status == 404 && j->on_not_found) {
|
||||
_cleanup_free_ char *new_url = NULL;
|
||||
if (IN_SET(protocol, CURLPROTO_HTTP, CURLPROTO_HTTPS)) {
|
||||
long status;
|
||||
|
||||
/* This resource wasn't found, but the implementor wants to maybe let us know a new URL, query for it. */
|
||||
r = j->on_not_found(j, &new_url);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
|
||||
if (code != CURLE_OK) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to retrieve response code: %s", curl_easy_strerror(code));
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (r > 0) { /* A new url to use */
|
||||
assert(new_url);
|
||||
if (status == 304) {
|
||||
log_info("Image already downloaded. Skipping download.");
|
||||
j->etag_exists = true;
|
||||
r = 0;
|
||||
goto finish;
|
||||
} else if (status >= 300) {
|
||||
|
||||
r = pull_job_restart(j, new_url);
|
||||
if (status == 404 && j->on_not_found) {
|
||||
_cleanup_free_ char *new_url = NULL;
|
||||
|
||||
/* This resource wasn't found, but the implementor wants to maybe let us know a new URL, query for it. */
|
||||
r = j->on_not_found(j, &new_url);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
code = curl_easy_getinfo(j->curl, CURLINFO_RESPONSE_CODE, &status);
|
||||
if (code != CURLE_OK) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to retrieve response code: %s", curl_easy_strerror(code));
|
||||
goto finish;
|
||||
if (r > 0) { /* A new url to use */
|
||||
assert(new_url);
|
||||
|
||||
r = pull_job_restart(j, new_url);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
code = curl_easy_getinfo(j->curl, CURLINFO_RESPONSE_CODE, &status);
|
||||
if (code != CURLE_OK) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to retrieve response code: %s", curl_easy_strerror(code));
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (status == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
if (status == 0)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
r = log_error_errno(
|
||||
status == 404 ? SYNTHETIC_ERRNO(ENOMEDIUM) : SYNTHETIC_ERRNO(EIO), /* Make the most common error recognizable */
|
||||
"HTTP request to %s failed with code %li.", j->url, status);
|
||||
goto finish;
|
||||
} else if (status < 200) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EIO), "HTTP request to %s finished with unexpected code %li.", j->url, status);
|
||||
goto finish;
|
||||
r = log_error_errno(
|
||||
status == 404 ? SYNTHETIC_ERRNO(ENOMEDIUM) : SYNTHETIC_ERRNO(EIO), /* Make the most common error recognizable */
|
||||
"HTTP request to %s failed with code %li.", j->url, status);
|
||||
goto finish;
|
||||
} else if (status < 200) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EIO), "HTTP request to %s finished with unexpected code %li.", j->url, status);
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
||||
if (j->state != PULL_JOB_RUNNING) {
|
||||
@ -260,6 +272,8 @@ void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result) {
|
||||
}
|
||||
}
|
||||
|
||||
log_info("Acquired %s.", FORMAT_BYTES(j->written_uncompressed));
|
||||
|
||||
r = 0;
|
||||
|
||||
finish:
|
||||
@ -292,7 +306,7 @@ static int pull_job_write_uncompressed(const void *p, size_t sz, void *userdata)
|
||||
|
||||
if (j->disk_fd >= 0) {
|
||||
|
||||
if (S_ISREG(j->disk_stat.st_mode)) {
|
||||
if (S_ISREG(j->disk_stat.st_mode) && j->offset == UINT64_MAX) {
|
||||
ssize_t n;
|
||||
|
||||
n = sparse_write(j->disk_fd, p, sz, 64);
|
||||
|
@ -835,7 +835,7 @@ int raw_pull_start(
|
||||
assert(!(flags & (PULL_SETTINGS|PULL_ROOTHASH|PULL_ROOTHASH_SIGNATURE|PULL_VERITY)) || !(flags & PULL_DIRECT));
|
||||
assert(!(flags & (PULL_SETTINGS|PULL_ROOTHASH|PULL_ROOTHASH_SIGNATURE|PULL_VERITY)) || !checksum);
|
||||
|
||||
if (!http_url_is_valid(url))
|
||||
if (!http_url_is_valid(url) && !file_url_is_valid(url))
|
||||
return -EINVAL;
|
||||
|
||||
if (local && !pull_validate_local(local, flags))
|
||||
|
@ -597,7 +597,7 @@ int tar_pull_start(
|
||||
assert(!(flags & PULL_SETTINGS) || !(flags & PULL_DIRECT));
|
||||
assert(!(flags & PULL_SETTINGS) || !checksum);
|
||||
|
||||
if (!http_url_is_valid(url))
|
||||
if (!http_url_is_valid(url) && !file_url_is_valid(url))
|
||||
return -EINVAL;
|
||||
|
||||
if (local && !pull_validate_local(local, flags))
|
||||
|
@ -110,7 +110,7 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
|
||||
int r;
|
||||
|
||||
url = argv[1];
|
||||
if (!http_url_is_valid(url))
|
||||
if (!http_url_is_valid(url) && !file_url_is_valid(url))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "URL '%s' is not valid.", url);
|
||||
|
||||
if (argc >= 3)
|
||||
@ -183,7 +183,7 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
|
||||
int r;
|
||||
|
||||
url = argv[1];
|
||||
if (!http_url_is_valid(url))
|
||||
if (!http_url_is_valid(url) && !file_url_is_valid(url))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "URL '%s' is not valid.", url);
|
||||
|
||||
if (argc >= 3)
|
||||
|
@ -2125,7 +2125,7 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
|
||||
assert(bus);
|
||||
|
||||
remote = argv[1];
|
||||
if (!http_url_is_valid(remote))
|
||||
if (!http_url_is_valid(remote) && !file_url_is_valid(remote))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"URL '%s' is not valid.", remote);
|
||||
|
||||
@ -2181,7 +2181,7 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
|
||||
assert(bus);
|
||||
|
||||
remote = argv[1];
|
||||
if (!http_url_is_valid(remote))
|
||||
if (!http_url_is_valid(remote) && !file_url_is_valid(remote))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"URL '%s' is not valid.", remote);
|
||||
|
||||
|
@ -36,16 +36,29 @@ bool http_url_is_valid(const char *url) {
|
||||
return ascii_is_valid(p);
|
||||
}
|
||||
|
||||
bool file_url_is_valid(const char *url) {
|
||||
const char *p;
|
||||
|
||||
if (isempty(url))
|
||||
return false;
|
||||
|
||||
p = startswith(url, "file:/");
|
||||
if (isempty(p))
|
||||
return false;
|
||||
|
||||
return ascii_is_valid(p);
|
||||
}
|
||||
|
||||
bool documentation_url_is_valid(const char *url) {
|
||||
const char *p;
|
||||
|
||||
if (isempty(url))
|
||||
return false;
|
||||
|
||||
if (http_url_is_valid(url))
|
||||
if (http_url_is_valid(url) || file_url_is_valid(url))
|
||||
return true;
|
||||
|
||||
p = STARTSWITH_SET(url, "file:/", "info:", "man:");
|
||||
p = STARTSWITH_SET(url, "info:", "man:");
|
||||
if (isempty(p))
|
||||
return false;
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "macro.h"
|
||||
|
||||
bool http_url_is_valid(const char *url) _pure_;
|
||||
bool file_url_is_valid(const char *url) _pure_;
|
||||
|
||||
bool documentation_url_is_valid(const char *url) _pure_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user