summaryrefslogtreecommitdiffstats
path: root/fileio.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 16:15:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 16:15:00 +0000
commited8873b14671073b4bd24d788dc61bcbf4fdfb14 (patch)
treed21da19c0d16a3169acbd9680382ceccad2bcad2 /fileio.c
parentAdding debian version 3.2.7-1. (diff)
downloadrsync-ed8873b14671073b4bd24d788dc61bcbf4fdfb14.tar.xz
rsync-ed8873b14671073b4bd24d788dc61bcbf4fdfb14.zip
Merging upstream version 3.3.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fileio.c')
-rw-r--r--fileio.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/fileio.c b/fileio.c
index f80af19..69c9a7b 100644
--- a/fileio.c
+++ b/fileio.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 1998 Andrew Tridgell
* Copyright (C) 2002 Martin Pool
- * Copyright (C) 2004-2020 Wayne Davison
+ * Copyright (C) 2004-2023 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -40,30 +40,34 @@ OFF_T preallocated_len = 0;
static OFF_T sparse_seek = 0;
static OFF_T sparse_past_write = 0;
-int sparse_end(int f, OFF_T size)
+int sparse_end(int f, OFF_T size, int updating_basis_or_equiv)
{
- int ret;
-
- sparse_past_write = 0;
-
- if (!sparse_seek)
- return 0;
+ int ret = 0;
+ if (updating_basis_or_equiv) {
+ if (sparse_seek && do_punch_hole(f, sparse_past_write, sparse_seek) < 0)
+ ret = -1;
+#ifdef HAVE_FTRUNCATE /* A compilation formality -- in-place requires ftruncate() */
+ else /* Just in case the original file was longer */
+ ret = do_ftruncate(f, size);
+#endif
+ } else if (sparse_seek) {
#ifdef HAVE_FTRUNCATE
- ret = do_ftruncate(f, size);
+ ret = do_ftruncate(f, size);
#else
- if (do_lseek(f, sparse_seek-1, SEEK_CUR) != size-1)
- ret = -1;
- else {
- do {
- ret = write(f, "", 1);
- } while (ret < 0 && errno == EINTR);
-
- ret = ret <= 0 ? -1 : 0;
- }
+ if (do_lseek(f, sparse_seek-1, SEEK_CUR) != size-1)
+ ret = -1;
+ else {
+ do {
+ ret = write(f, "", 1);
+ } while (ret < 0 && errno == EINTR);
+
+ ret = ret <= 0 ? -1 : 0;
+ }
#endif
+ }
- sparse_seek = 0;
+ sparse_past_write = sparse_seek = 0;
return ret;
}