X Tutup
Skip to content

Commit bf284ae

Browse files
committed
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)
1 parent 53e03c9 commit bf284ae

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/import/import-raw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ static int raw_import_write(const void *p, size_t sz, void *userdata) {
368368
}
369369

370370
/* Generate sparse file if we created/truncated the file */
371-
if (S_ISREG(i->output_stat.st_mode)) {
371+
if (S_ISREG(i->output_stat.st_mode) && i->offset == UINT64_MAX) {
372372
ssize_t n;
373373

374374
n = sparse_write(i->output_fd, p, sz, 64);

src/import/pull-job.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static int pull_job_write_uncompressed(const void *p, size_t sz, void *userdata)
306306

307307
if (j->disk_fd >= 0) {
308308

309-
if (S_ISREG(j->disk_stat.st_mode)) {
309+
if (S_ISREG(j->disk_stat.st_mode) && j->offset == UINT64_MAX) {
310310
ssize_t n;
311311

312312
n = sparse_write(j->disk_fd, p, sz, 64);

0 commit comments

Comments
 (0)
X Tutup