import: enable sparse file writing logic only for files we create

Only if we create a file we know for sure that it is empty and hence our
sparse file logic of skipping over NUL bytes can can work. If we hwoever
are called to write data to some existing file/block device, we must do
regular writes to override everything that might be in place before.

Hence, conditionalize sparse file writing on the write offset not being
configured (which is how we internally distinguish write to existing
file and write to new file)
This commit is contained in:
Lennart Poettering
2021-08-19 17:22:18 +02:00
parent 53e03c9692
commit bf284aee23
2 changed files with 2 additions and 2 deletions

View File

@@ -368,7 +368,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);

View File

@@ -306,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);