-rw-r--r-- | scan-tree.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/scan-tree.c b/scan-tree.c index 627af1b..e5a4baf 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -174,68 +174,69 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) goto end; } if (is_git_dir(fmt("%s/.git", path))) { add_repo(base, fmt("%s/.git", path), fn); goto end; } while((ent = readdir(dir)) != NULL) { if (ent->d_name[0] == '.') { if (ent->d_name[1] == '\0') continue; if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') continue; if (!ctx.cfg.scan_hidden_path) continue; } buf = malloc(strlen(path) + strlen(ent->d_name) + 2); if (!buf) { fprintf(stderr, "Alloc error on %s: %s (%d)\n", path, strerror(errno), errno); exit(1); } sprintf(buf, "%s/%s", path, ent->d_name); if (stat(buf, &st)) { fprintf(stderr, "Error checking path %s: %s (%d)\n", buf, strerror(errno), errno); free(buf); continue; } if (S_ISDIR(st.st_mode)) scan_path(base, buf, fn); free(buf); } end: closedir(dir); } #define lastc(s) s[strlen(s) - 1] void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) { char line[MAX_PATH * 2], *z; FILE *projects; int err; projects = fopen(projectsfile, "r"); if (!projects) { fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n", projectsfile, strerror(errno), errno); + return; } while (fgets(line, sizeof(line), projects) != NULL) { for (z = &lastc(line); strlen(line) && strchr("\n\r", *z); z = &lastc(line)) *z = '\0'; if (strlen(line)) scan_path(path, fmt("%s/%s", path, line), fn); } if ((err = ferror(projects))) { fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n", projectsfile, strerror(err), err); } fclose(projects); } void scan_tree(const char *path, repo_config_fn fn) { scan_path(path, path, fn); } |