Question about nALFS' file logging functions

Neven Has haski at sezampro.yu
Wed Oct 9 19:18:18 PDT 2002


On Wed, Oct 09, 2002 at 09:25:30PM +0200, Neven Has wrote:
> I have put this (and ignoring files) in TODO (which I'll have to start
> bziping soon ;).
> 
> I'll send a patch for that pruned_directory_printing tomorrow. But the
> above should be done soon as well, I do plan to release a new version
> earlier.

Well, it was easier than I though. The patch allows pruning files and
completely ignoring directories specified in the prune list.


Neven
-------------- next part --------------
===== src/find.c 1.10 vs edited =====
--- 1.10/src/find.c	Tue Apr 30 13:00:20 2002
+++ edited/src/find.c	Thu Oct 10 00:49:07 2002
@@ -162,26 +162,26 @@
 		return 1;
 	}
 
+	/* Check if a file is in the prune list. */
+	for (i = 0; prunes[i]; i++) {
+		if (strcmp(filename, prunes[i]) == 0) {
+			Debug_logging("In prune list: %s", filename);
+			return 0;
+		}
+	}
+
+	/* Not in the prune list, print it. */
 	if (time_stamp == -1 || statbuf.st_ctime > time_stamp) {
 		print_file(filename, &statbuf);
 		putc('\n', fp);
 	}
 
 	if (! S_ISDIR(statbuf.st_mode)) {
-		/* It's NOT a directory. */
+		/* It's not a directory, we're done. */
 		return 0;
-
-	} else if (prunes) { /* It's a directory,
-			      *	check if it's in the prune list.
-			      */
-		for (i = 0; prunes[i]; i++) {
-			if (strcmp(filename, prunes[i]) == 0) {
-				Debug_logging("In prune list: %s", filename);
-				return 0;
-			}
-		}
 	}
 
+	/* It's a directory, read it. */
 
 	if (! (dir = opendir(filename))) {
 		pstatus(COL_WAR, "%s: %s", filename, strerror(errno));
@@ -213,29 +213,32 @@
 	return status;
 }
 
-static void init_prune_list(const char *root, const char *prune_string)
+static void init_prune_list(const char *root, const char *string_)
 {
 	int i = 0;
-	char *dir;
-	char *string = xstrdup(prune_string);
-	char resolved_dir[PATH_MAX];
+	char *file;
+	char *string = xstrdup(string_);
+	char resolved_path[PATH_MAX];
 
 
-	for (dir = strtok(string, WHITE_SPACE); dir;
-	dir = strtok(NULL, WHITE_SPACE)) {
-		char tmp[strlen(root) + strlen(dir) + 2];
+	for (file = strtok(string, WHITE_SPACE); file;
+	file = strtok(NULL, WHITE_SPACE)) {
+		char tmp[strlen(root) + strlen(file) + 2];
 
-		sprintf(tmp, "%s/%s", root, dir);
+		sprintf(tmp, "%s/%s", root, file);
 
-		if (realpath(tmp, resolved_dir) == NULL) {
+		/* TODO: File is added in the prune list,
+		 *       only if it already exists.
+		 */
+		if (realpath(tmp, resolved_path) == NULL) {
 			continue;
 		}
 
 		i++;
 
 		prunes = xrealloc(prunes, (i + 1) * sizeof *prunes);
-		
-		prunes[i-1] = xstrdup(resolved_dir);
+
+		prunes[i-1] = xstrdup(resolved_path);
 		prunes[i] = NULL;
 	}
 
@@ -267,9 +270,8 @@
 	if (find_prunes_ && strlen(find_prunes_)) {
 		init_prune_list(root, find_prunes_);
 
-		/* Print prune list. */
-		if (prunes) {
-			pstatus(COL_INF, "Ignoring directories:");
+		if (prunes) { /* Print prune list. */
+			pstatus(COL_INF, "Ignoring these files:");
 
 			for (i = 0; prunes[i]; i++) {
 				pstatus(COL_INF, "    %s", prunes[i]);


More information about the alfs-discuss mailing list