Commits

Serge Zaitsev committed efd8d96

skip hidden/backup files

  • Participants
  • Parent commits 061cebe

Comments (0)

Files changed (1)

 	while ((entry = readdir(dir)) != NULL) {
 		struct stat st;
 		char path[256];
-		snprintf(path, sizeof(path)-1, "%s/%s", root, entry->d_name);
+		char *name = entry->d_name;
+		if (name[0] == '.' || strcmp(name, "..") == 0 || strcmp(name, ".") == 0
+				|| name[0] == '#' || name[0] == '~' || name[strlen(name)-1] == '~') {
+			continue;
+		}
+
+		snprintf(path, sizeof(path)-1, "%s/%s", root, name);
 		if (stat(path, &st) < 0) {
 			return -errno;
 		}
 		if (S_ISREG(st.st_mode)) {
-			printf("indexing %s\n", entry->d_name);
+			printf("indexing %s\n", path);
 			cb(path, arg);
-		} else if (S_ISDIR(st.st_mode) && strcmp(entry->d_name, ".") != 0 
-				&& strcmp(entry->d_name, "..") != 0) {
+		} else if (S_ISDIR(st.st_mode)) {
 			scandirs(path, cb, arg);
 		}
 	}