summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2019-01-09 11:13:54 -0400
committerJoey Hess <joeyh@joeyh.name>2019-01-09 11:13:54 -0400
commitc8086c5f8803cef57b3e6bad30f25d6544b618c2 (patch)
treee228415126ca03edfa4ff80309f6f04876db6c72
parentd63bb12bb6c354d15e57e4642dee3d143bb78895 (diff)
downloadmoreutils-c8086c5f8803cef57b3e6bad30f25d6544b618c2.tar.gz
sponge: Fix bug in -a mode that doubled original content of file
Occurred when the temp file is located on a different filesystem. It seems that append mode was put in on that file open without realizing the consequences of it. Bug has been present since the first -a patch. This commit was sponsored by Peter on Patreon.
-rw-r--r--debian/changelog2
-rw-r--r--sponge.c2
2 files changed, 3 insertions, 1 deletions
diff --git a/debian/changelog b/debian/changelog
index 3a62905..f933dc7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,8 @@ moreutils (0.63) UNRELEASED; urgency=medium
Thanks, Stig Palmquist.
* ts: Fix ts -m %.s to not output negative microseconds.
Thanks, Dima Kogan
+ * sponge: Fix bug in -a mode that doubled original content of file when
+ the temp file is located on a different filesystem.
-- Joey Hess <id@joeyh.name> Wed, 22 Aug 2018 21:00:58 -0400
diff --git a/sponge.c b/sponge.c
index 09d3971..f852ad5 100644
--- a/sponge.c
+++ b/sponge.c
@@ -372,7 +372,7 @@ int main (int argc, char **argv) {
}
else {
/* Fall back to slow copy. */
- outfile = fopen(outname, append ? "a" : "w");
+ outfile = fopen(outname, "w");
if (!outfile) {
perror("error opening output file");
exit(1);