mirror of
https://github.com/systemd/systemd.git
synced 2025-03-21 02:50:18 +03:00
Merge pull request #18408 from poettering/import-fixlets3
5 more small fixes to importd
This commit is contained in:
commit
e01b47a500
@ -83,6 +83,13 @@ int import_uncompress_detect(ImportCompress *c, const void *data, size_t size) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void import_uncompress_force_off(ImportCompress *c) {
|
||||
assert(c);
|
||||
|
||||
c->type = IMPORT_COMPRESS_UNCOMPRESSED;
|
||||
c->encoding = false;
|
||||
}
|
||||
|
||||
int import_uncompress(ImportCompress *c, const void *data, size_t size, ImportCompressCallback callback, void *userdata) {
|
||||
int r;
|
||||
|
||||
@ -125,9 +132,11 @@ int import_uncompress(ImportCompress *c, const void *data, size_t size, ImportCo
|
||||
if (!IN_SET(lzr, LZMA_OK, LZMA_STREAM_END))
|
||||
return -EIO;
|
||||
|
||||
r = callback(buffer, sizeof(buffer) - c->xz.avail_out, userdata);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (c->xz.avail_out < sizeof(buffer)) {
|
||||
r = callback(buffer, sizeof(buffer) - c->xz.avail_out, userdata);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@ -146,9 +155,11 @@ int import_uncompress(ImportCompress *c, const void *data, size_t size, ImportCo
|
||||
if (!IN_SET(r, Z_OK, Z_STREAM_END))
|
||||
return -EIO;
|
||||
|
||||
r = callback(buffer, sizeof(buffer) - c->gzip.avail_out, userdata);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (c->gzip.avail_out < sizeof(buffer)) {
|
||||
r = callback(buffer, sizeof(buffer) - c->gzip.avail_out, userdata);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@ -168,9 +179,11 @@ int import_uncompress(ImportCompress *c, const void *data, size_t size, ImportCo
|
||||
if (!IN_SET(r, BZ_OK, BZ_STREAM_END))
|
||||
return -EIO;
|
||||
|
||||
r = callback(buffer, sizeof(buffer) - c->bzip2.avail_out, userdata);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (c->bzip2.avail_out < sizeof(buffer)) {
|
||||
r = callback(buffer, sizeof(buffer) - c->bzip2.avail_out, userdata);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -37,6 +37,7 @@ typedef int (*ImportCompressCallback)(const void *data, size_t size, void *userd
|
||||
void import_compress_free(ImportCompress *c);
|
||||
|
||||
int import_uncompress_detect(ImportCompress *c, const void *data, size_t size);
|
||||
void import_uncompress_force_off(ImportCompress *c);
|
||||
int import_uncompress(ImportCompress *c, const void *data, size_t size, ImportCompressCallback callback, void *userdata);
|
||||
|
||||
int import_compress_init(ImportCompress *c, ImportCompressType t);
|
||||
|
@ -64,10 +64,7 @@ RawImport* raw_import_unref(RawImport *i) {
|
||||
|
||||
sd_event_unref(i->event);
|
||||
|
||||
if (i->temp_path) {
|
||||
(void) unlink(i->temp_path);
|
||||
free(i->temp_path);
|
||||
}
|
||||
unlink_and_free(i->temp_path);
|
||||
|
||||
import_compress_free(&i->compress);
|
||||
|
||||
@ -316,27 +313,23 @@ static int raw_import_process(RawImport *i) {
|
||||
r = log_error_errno(errno, "Failed to read input file: %m");
|
||||
goto finish;
|
||||
}
|
||||
if (l == 0) {
|
||||
if (i->compress.type == IMPORT_COMPRESS_UNKNOWN) {
|
||||
log_error("Premature end of file.");
|
||||
r = -EIO;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
r = raw_import_finish(i);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
i->buffer_size += l;
|
||||
|
||||
if (i->compress.type == IMPORT_COMPRESS_UNKNOWN) {
|
||||
r = import_uncompress_detect(&i->compress, i->buffer, i->buffer_size);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to detect file compression: %m");
|
||||
goto finish;
|
||||
|
||||
if (l == 0) { /* EOF */
|
||||
log_debug("File too short to be compressed, as no compression signature fits in, thus assuming uncompressed.");
|
||||
import_uncompress_force_off(&i->compress);
|
||||
} else {
|
||||
r = import_uncompress_detect(&i->compress, i->buffer, i->buffer_size);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to detect file compression: %m");
|
||||
goto finish;
|
||||
}
|
||||
if (r == 0) /* Need more data */
|
||||
return 0;
|
||||
}
|
||||
if (r == 0) /* Need more data */
|
||||
return 0;
|
||||
|
||||
r = raw_import_open_disk(i);
|
||||
if (r < 0)
|
||||
@ -345,10 +338,8 @@ static int raw_import_process(RawImport *i) {
|
||||
r = raw_import_try_reflink(i);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
if (r > 0) {
|
||||
r = raw_import_finish(i);
|
||||
goto finish;
|
||||
}
|
||||
if (r > 0)
|
||||
goto complete;
|
||||
}
|
||||
|
||||
r = import_uncompress(&i->compress, i->buffer, i->buffer_size, raw_import_write, i);
|
||||
@ -360,10 +351,16 @@ static int raw_import_process(RawImport *i) {
|
||||
i->written_compressed += i->buffer_size;
|
||||
i->buffer_size = 0;
|
||||
|
||||
if (l == 0) /* EOF */
|
||||
goto complete;
|
||||
|
||||
raw_import_report_progress(i);
|
||||
|
||||
return 0;
|
||||
|
||||
complete:
|
||||
r = raw_import_finish(i);
|
||||
|
||||
finish:
|
||||
if (i->on_finished)
|
||||
i->on_finished(i, r, i->userdata);
|
||||
|
@ -73,10 +73,7 @@ TarImport* tar_import_unref(TarImport *i) {
|
||||
(void) wait_for_terminate(i->tar_pid, NULL);
|
||||
}
|
||||
|
||||
if (i->temp_path) {
|
||||
(void) rm_rf(i->temp_path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
|
||||
free(i->temp_path);
|
||||
}
|
||||
rm_rf_subvolume_and_free(i->temp_path);
|
||||
|
||||
import_compress_free(&i->compress);
|
||||
|
||||
@ -262,27 +259,23 @@ static int tar_import_process(TarImport *i) {
|
||||
r = log_error_errno(errno, "Failed to read input file: %m");
|
||||
goto finish;
|
||||
}
|
||||
if (l == 0) {
|
||||
if (i->compress.type == IMPORT_COMPRESS_UNKNOWN) {
|
||||
log_error("Premature end of file.");
|
||||
r = -EIO;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
r = tar_import_finish(i);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
i->buffer_size += l;
|
||||
|
||||
if (i->compress.type == IMPORT_COMPRESS_UNKNOWN) {
|
||||
r = import_uncompress_detect(&i->compress, i->buffer, i->buffer_size);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to detect file compression: %m");
|
||||
goto finish;
|
||||
|
||||
if (l == 0) { /* EOF */
|
||||
log_debug("File too short to be compressed, as no compression signature fits in, thus assuming uncompressed.");
|
||||
import_uncompress_force_off(&i->compress);
|
||||
} else {
|
||||
r = import_uncompress_detect(&i->compress, i->buffer, i->buffer_size);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to detect file compression: %m");
|
||||
goto finish;
|
||||
}
|
||||
if (r == 0) /* Need more data */
|
||||
return 0;
|
||||
}
|
||||
if (r == 0) /* Need more data */
|
||||
return 0;
|
||||
|
||||
r = tar_import_fork_tar(i);
|
||||
if (r < 0)
|
||||
@ -298,6 +291,11 @@ static int tar_import_process(TarImport *i) {
|
||||
i->written_compressed += i->buffer_size;
|
||||
i->buffer_size = 0;
|
||||
|
||||
if (l == 0) { /* EOF */
|
||||
r = tar_import_finish(i);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
tar_import_report_progress(i);
|
||||
|
||||
return 0;
|
||||
|
@ -490,12 +490,15 @@ finish:
|
||||
|
||||
int pull_verify(ImportVerify verify,
|
||||
PullJob *main_job,
|
||||
PullJob *roothash_job,
|
||||
PullJob *settings_job,
|
||||
PullJob *checksum_job,
|
||||
PullJob *signature_job) {
|
||||
PullJob *signature_job,
|
||||
PullJob *settings_job,
|
||||
PullJob *roothash_job,
|
||||
PullJob *roothash_signature_job,
|
||||
PullJob *verity_job) {
|
||||
|
||||
VerificationStyle style;
|
||||
PullJob *j;
|
||||
int r;
|
||||
|
||||
assert(main_job);
|
||||
@ -513,17 +516,11 @@ int pull_verify(ImportVerify verify,
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
|
||||
"Checksum is empty, cannot verify.");
|
||||
|
||||
r = verify_one(checksum_job, main_job);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = verify_one(checksum_job, roothash_job);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = verify_one(checksum_job, settings_job);
|
||||
if (r < 0)
|
||||
return r;
|
||||
FOREACH_POINTER(j, main_job, settings_job, roothash_job, roothash_signature_job, verity_job) {
|
||||
r = verify_one(checksum_job, j);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (verify == IMPORT_VERIFY_CHECKSUM)
|
||||
return 0;
|
||||
|
@ -27,7 +27,7 @@ int pull_make_path(const char *url, const char *etag, const char *image_root, co
|
||||
int pull_make_auxiliary_job(PullJob **ret, const char *url, int (*strip_suffixes)(const char *name, char **ret), const char *suffix, CurlGlue *glue, PullJobFinished on_finished, void *userdata);
|
||||
int pull_make_verification_jobs(PullJob **ret_checksum_job, PullJob **ret_signature_job, ImportVerify verify, const char *url, CurlGlue *glue, PullJobFinished on_finished, void *userdata);
|
||||
|
||||
int pull_verify(ImportVerify verify, PullJob *main_job, PullJob *roothash_job, PullJob *settings_job, PullJob *checksum_job, PullJob *signature_job);
|
||||
int pull_verify(ImportVerify verify, PullJob *main_job, PullJob *checksum_job, PullJob *signature_job, PullJob *settings_job, PullJob *roothash_job, PullJob *roothash_signature_job, PullJob *verity_job);
|
||||
|
||||
typedef enum VerificationStyle {
|
||||
VERIFICATION_PER_FILE, /* SuSE-style ".sha256" files with inline gpg signature */
|
||||
|
@ -542,7 +542,14 @@ static void raw_pull_job_on_finished(PullJob *j) {
|
||||
|
||||
raw_pull_report_progress(i, RAW_VERIFYING);
|
||||
|
||||
r = pull_verify(i->verify, i->raw_job, i->roothash_job, i->settings_job, i->checksum_job, i->signature_job);
|
||||
r = pull_verify(i->verify,
|
||||
i->raw_job,
|
||||
i->checksum_job,
|
||||
i->signature_job,
|
||||
i->settings_job,
|
||||
i->roothash_job,
|
||||
i->roothash_signature_job,
|
||||
i->verity_job);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
|
@ -336,7 +336,14 @@ static void tar_pull_job_on_finished(PullJob *j) {
|
||||
|
||||
tar_pull_report_progress(i, TAR_VERIFYING);
|
||||
|
||||
r = pull_verify(i->verify, i->tar_job, NULL, i->settings_job, i->checksum_job, i->signature_job);
|
||||
r = pull_verify(i->verify,
|
||||
i->tar_job,
|
||||
i->checksum_job,
|
||||
i->signature_job,
|
||||
i->settings_job,
|
||||
/* roothash_job = */ NULL,
|
||||
/* roothash_signature_job = */ NULL,
|
||||
/* verity_job = */ NULL);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
|
@ -212,7 +212,8 @@ static int help(int argc, char *argv[], void *userdata) {
|
||||
" 'checksum', 'signature'\n"
|
||||
" --settings=BOOL Download settings file with image\n"
|
||||
" --roothash=BOOL Download root hash file with image\n"
|
||||
" --roothash-sigature=BOOL Download root hash signature file with image\n"
|
||||
" --roothash-signature=BOOL\n"
|
||||
" Download root hash signature file with image\n"
|
||||
" --verity=BOOL Download verity file with image\n"
|
||||
" --image-root=PATH Image root directory\n\n"
|
||||
"Commands:\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user