]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
shred: avoid data write pass with --size=0
authorPádraig Brady <P@draigBrady.com>
Thu, 7 Nov 2013 12:32:29 +0000 (12:32 +0000)
committerPádraig Brady <P@draigBrady.com>
Fri, 8 Nov 2013 13:39:35 +0000 (13:39 +0000)
* 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.

src/shred.c
tests/misc/shred-passes.sh

index 6ff8322c9c06fd88923b0c7430a0f7ff05531725..95a255a5b58f294fe10b46c699b3342a5a9b13d4 100644 (file)
@@ -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)
index cfdd68e982cae2996f63ec4326d182c5a78ca6cf..938683bcec10506cc2d0b0b5aed691b1877d7ed4 100755 (executable)
@@ -31,9 +31,21 @@ shred: f: removing
 shred: f: renamed to 0
 shred: f: removed" > exp || framework_failure_
 
-
 shred -v -u f 2>out || fail=1
 
 compare exp out || fail=1
 
+# Likewise but with --exact to bypass the
+# data passes for the zero length file
+touch f || framework_failure_
+echo "\
+shred: f: removing
+shred: f: renamed to 0
+shred: f: removed" > exp || framework_failure_
+
+shred -x -v -u f 2>out || fail=1
+
+compare exp out || fail=1
+
+
 Exit $fail