summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-12-18 16:00:49 +0000
committerJim Meyering <jim@meyering.net>1999-12-18 16:00:49 +0000
commit04aa739146c8a926aab6da7a046f1844e414899f (patch)
tree6fee19b3f9e2df750b5d2afc819e22cdb124cb89 /src
parentac31ad442b696696df0a0b14fa3c70e21c129081 (diff)
downloadcoreutils-04aa739146c8a926aab6da7a046f1844e414899f.tar.xz
(wipename): When repeatedly renaming a file, making the name shorter
and shorter, skip to the next shorter length length if a rename fails (e.g. due to permission denied). Otherwise, this loop would iterate for so long that shred would appear to be stuck in an infinite loop for any but the shortest file names.
Diffstat (limited to 'src')
-rw-r--r--src/shred.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/shred.c b/src/shred.c
index e8b7c8d08..d192a1a33 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -1589,22 +1589,34 @@ wipename (char *oldname, char const *qoldname, struct Options const *flags)
do
{
struct stat st;
- if (lstat (newname, &st) < 0 && rename (oldname, newname) == 0)
+ if (lstat (newname, &st) < 0)
{
- if (dir_fd < 0
- || (fdatasync (dir_fd) < 0 && fsync (dir_fd) < 0))
- sync (); /* Force directory out */
- if (flags->verbose)
+ if (rename (oldname, newname) == 0)
{
- /*
- * People seem to understand this better than talking
- * about renaming oldname. newname doesn't need
- * quoting because we picked it.
- */
- error (0, 0, _("%s: renamed to `%s'"), qoldname, newname);
+ if (dir_fd < 0
+ || (fdatasync (dir_fd) < 0 && fsync (dir_fd) < 0))
+ sync (); /* Force directory out */
+ if (flags->verbose)
+ {
+ /*
+ * People seem to understand this better than talking
+ * about renaming oldname. newname doesn't need
+ * quoting because we picked it.
+ */
+ error (0, 0, _("%s: renamed to `%s'"), qoldname, newname);
+ }
+ memcpy (oldname + (base - newname), base, len + 1);
+ break;
}
- memcpy (oldname + (base - newname), base, len + 1);
- break;
+ else
+ {
+ /* The rename failed: give up on this length. */
+ break;
+ }
+ }
+ else
+ {
+ /* newname exists, so increment BASE so we use another */
}
}
while (!incname (base, len));