summaryrefslogtreecommitdiff
path: root/src/shred.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2013-11-07 12:32:29 +0000
committerPádraig Brady <P@draigBrady.com>2013-11-08 13:39:35 +0000
commit90181a5926e96f34b5ffff21b81a2874a846ff6f (patch)
tree6cdda1ab6f90c873542c11de9a6d1b9dab667242 /src/shred.c
parentc2eaef2f57153a22b6dc075b1adc9fde1a4eb7bd (diff)
downloadcoreutils-90181a5926e96f34b5ffff21b81a2874a846ff6f.tar.xz
shred: avoid data write pass with --size=0
* src/shred.c (dopass): Exit early to avoid redundant heap allocation, and more importantly avoiding a file sync when we're writting no data, as this can have side effects. Also with --verbose, this avoids printing of "pass status" which could be confusing as to whether data was actually written. * tests/misc/shred-passes.sh: Ensure the status for data passes are not written when not doing any data writes.
Diffstat (limited to 'src/shred.c')
-rw-r--r--src/shred.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/shred.c b/src/shred.c
index 6ff8322c9..95a255a5b 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -378,6 +378,10 @@ dopass (int fd, char const *qname, off_t *sizep, int type,
size_t soff; /* Offset into buffer for next write */
ssize_t ssize; /* Return value from write */
+ /* Do nothing for --size=0 or regular empty files with --exact. */
+ if (size == 0)
+ return 0;
+
/* Fill pattern buffer. Aligning it to a page so we can do direct I/O. */
size_t page_size = getpagesize ();
#define PERIODIC_OUTPUT_SIZE (60 * 1024)