mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
import: make sure we can import empty files
This commit is contained in:
parent
9f0b5640bd
commit
c9b6ebef8c
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -313,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)
|
||||
@ -342,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);
|
||||
@ -357,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);
|
||||
|
@ -259,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)
|
||||
@ -295,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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user