Package: tmpreaper
Version: 1.6.13+nmu1
Severity: normal
Tags: patch

What is happening with the current code:
Upon encountering a directory, the recursive subroutine to check and process
the directory is called prior to matching the directory name to the
configured protect strings. The result of this is that the contents of the
directory which matches a protect string will be removed if they themselves
do not match a protect string and are eligible to being removed by the
configured tmpreaper logic. After being returned from the recursion call,
the directory name is then checked against the configured protect strings
and is then skipped due to being positively matched. However, the contents
have already been removed.

What I expected:
Any file or directory is first matched against the configured protect
strings, and in the case of a directory, this directory is completely
skipped due to the fact that it positively matched a protect string. The
contents of that directory will never get processed and thus remain in tact.

The solution:
Put the protect match check block (if (FLAGS_PROTECT_P (flags)) {) before
the recursive directory check block (if (S_ISDIR (sb.st_mode)) {).


-- System Information:
Debian Release: 6.0.2
  APT prefers stable
  APT policy: (990, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-openvz-amd64 (SMP w/4 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash

Versions of packages tmpreaper depends on:
ii  debconf [debconf-2.0]         1.5.36.1   Debian configuration management sy
ii  libc6                         2.11.2-10  Embedded GNU C Library: Shared lib

tmpreaper recommends no packages.

tmpreaper suggests no packages.

-- debconf information excluded
--- tmpreaper.c.orig	2011-08-03 10:01:58.530126581 +0200
+++ tmpreaper.c	2011-08-03 10:02:51.008247226 +0200
@@ -467,6 +467,21 @@
 		    continue;
 		}
 
+                if (FLAGS_PROTECT_P (flags)) {
+		    skip = i = 0;
+		    do {
+			if (sb.st_ino == protect_table[i].inode) {
+			    message (LOG_VERBOSE,
+				     "Entry matching `--protect' pattern skipped. `%s'\n",
+				     protect_table[i].name);
+			    skip = 1;
+			    break;
+			}
+		    } while (protect_table[i++].name);
+		    if (skip)
+			continue;
+		}
+
 		if (S_ISDIR (sb.st_mode)) {
                     char *dst;
 
@@ -489,21 +504,6 @@
 			     (u_int) getpid(), ent->d_name);
 		}
 
-		if (FLAGS_PROTECT_P (flags)) {
-		    skip = i = 0;
-		    do {
-			if (sb.st_ino == protect_table[i].inode) {
-			    message (LOG_VERBOSE,
-				     "Entry matching `--protect' pattern skipped. `%s'\n",
-				     protect_table[i].name);
-			    skip = 1;
-			    break;
-			}
-		    } while (protect_table[i++].name);
-		    if (skip)
-			continue;
-		}
-
 		/* Decide whether to remove the file or not */
 		/* check for mtime on directory instead of atime if requested */
 		if ( FLAGS_MTIME_P(flags) ||

Reply via email to