-rw-r--r-- | scan-tree.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/scan-tree.c b/scan-tree.c index eda8c67..627af1b 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -138,96 +138,98 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) | |||
138 | while (slash && n && (slash = xstrrchr(rel, slash, '/'))) | 138 | while (slash && n && (slash = xstrrchr(rel, slash, '/'))) |
139 | n++; | 139 | n++; |
140 | } | 140 | } |
141 | if (slash && !n) { | 141 | if (slash && !n) { |
142 | *slash = '\0'; | 142 | *slash = '\0'; |
143 | repo->section = xstrdup(rel); | 143 | repo->section = xstrdup(rel); |
144 | *slash = '/'; | 144 | *slash = '/'; |
145 | if (!prefixcmp(repo->name, repo->section)) { | 145 | if (!prefixcmp(repo->name, repo->section)) { |
146 | repo->name += strlen(repo->section); | 146 | repo->name += strlen(repo->section); |
147 | if (*repo->name == '/') | 147 | if (*repo->name == '/') |
148 | repo->name++; | 148 | repo->name++; |
149 | } | 149 | } |
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 | ||
153 | p = fmt("%s/cgitrc", path); | 153 | p = fmt("%s/cgitrc", path); |
154 | if (!stat(p, &st)) { | 154 | if (!stat(p, &st)) { |
155 | config_fn = fn; | 155 | config_fn = fn; |
156 | parse_configfile(xstrdup(p), &repo_config); | 156 | parse_configfile(xstrdup(p), &repo_config); |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | static void scan_path(const char *base, const char *path, repo_config_fn fn) | 160 | static void scan_path(const char *base, const char *path, repo_config_fn fn) |
161 | { | 161 | { |
162 | DIR *dir = opendir(path); | 162 | DIR *dir = opendir(path); |
163 | struct dirent *ent; | 163 | struct dirent *ent; |
164 | char *buf; | 164 | char *buf; |
165 | struct stat st; | 165 | struct stat st; |
166 | 166 | ||
167 | if (!dir) { | 167 | if (!dir) { |
168 | fprintf(stderr, "Error opening directory %s: %s (%d)\n", | 168 | fprintf(stderr, "Error opening directory %s: %s (%d)\n", |
169 | path, strerror(errno), errno); | 169 | path, strerror(errno), errno); |
170 | return; | 170 | return; |
171 | } | 171 | } |
172 | if (is_git_dir(path)) { | 172 | if (is_git_dir(path)) { |
173 | add_repo(base, path, fn); | 173 | add_repo(base, path, fn); |
174 | goto end; | 174 | goto end; |
175 | } | 175 | } |
176 | if (is_git_dir(fmt("%s/.git", path))) { | 176 | if (is_git_dir(fmt("%s/.git", path))) { |
177 | add_repo(base, fmt("%s/.git", path), fn); | 177 | add_repo(base, fmt("%s/.git", path), fn); |
178 | goto end; | 178 | goto end; |
179 | } | 179 | } |
180 | while((ent = readdir(dir)) != NULL) { | 180 | while((ent = readdir(dir)) != NULL) { |
181 | if (ent->d_name[0] == '.') { | 181 | if (ent->d_name[0] == '.') { |
182 | if (ent->d_name[1] == '\0') | 182 | if (ent->d_name[1] == '\0') |
183 | continue; | 183 | continue; |
184 | if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') | 184 | if (ent->d_name[1] == '.' && ent->d_name[2] == '\0') |
185 | continue; | 185 | continue; |
186 | if (!ctx.cfg.scan_hidden_path) | ||
187 | continue; | ||
186 | } | 188 | } |
187 | buf = malloc(strlen(path) + strlen(ent->d_name) + 2); | 189 | buf = malloc(strlen(path) + strlen(ent->d_name) + 2); |
188 | if (!buf) { | 190 | if (!buf) { |
189 | fprintf(stderr, "Alloc error on %s: %s (%d)\n", | 191 | fprintf(stderr, "Alloc error on %s: %s (%d)\n", |
190 | path, strerror(errno), errno); | 192 | path, strerror(errno), errno); |
191 | exit(1); | 193 | exit(1); |
192 | } | 194 | } |
193 | sprintf(buf, "%s/%s", path, ent->d_name); | 195 | sprintf(buf, "%s/%s", path, ent->d_name); |
194 | if (stat(buf, &st)) { | 196 | if (stat(buf, &st)) { |
195 | fprintf(stderr, "Error checking path %s: %s (%d)\n", | 197 | fprintf(stderr, "Error checking path %s: %s (%d)\n", |
196 | buf, strerror(errno), errno); | 198 | buf, strerror(errno), errno); |
197 | free(buf); | 199 | free(buf); |
198 | continue; | 200 | continue; |
199 | } | 201 | } |
200 | if (S_ISDIR(st.st_mode)) | 202 | if (S_ISDIR(st.st_mode)) |
201 | scan_path(base, buf, fn); | 203 | scan_path(base, buf, fn); |
202 | free(buf); | 204 | free(buf); |
203 | } | 205 | } |
204 | end: | 206 | end: |
205 | closedir(dir); | 207 | closedir(dir); |
206 | } | 208 | } |
207 | 209 | ||
208 | #define lastc(s) s[strlen(s) - 1] | 210 | #define lastc(s) s[strlen(s) - 1] |
209 | 211 | ||
210 | void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) | 212 | void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) |
211 | { | 213 | { |
212 | char line[MAX_PATH * 2], *z; | 214 | char line[MAX_PATH * 2], *z; |
213 | FILE *projects; | 215 | FILE *projects; |
214 | int err; | 216 | int err; |
215 | 217 | ||
216 | projects = fopen(projectsfile, "r"); | 218 | projects = fopen(projectsfile, "r"); |
217 | if (!projects) { | 219 | if (!projects) { |
218 | fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n", | 220 | fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n", |
219 | projectsfile, strerror(errno), errno); | 221 | projectsfile, strerror(errno), errno); |
220 | } | 222 | } |
221 | while (fgets(line, sizeof(line), projects) != NULL) { | 223 | while (fgets(line, sizeof(line), projects) != NULL) { |
222 | for (z = &lastc(line); | 224 | for (z = &lastc(line); |
223 | strlen(line) && strchr("\n\r", *z); | 225 | strlen(line) && strchr("\n\r", *z); |
224 | z = &lastc(line)) | 226 | z = &lastc(line)) |
225 | *z = '\0'; | 227 | *z = '\0'; |
226 | if (strlen(line)) | 228 | if (strlen(line)) |
227 | scan_path(path, fmt("%s/%s", path, line), fn); | 229 | scan_path(path, fmt("%s/%s", path, line), fn); |
228 | } | 230 | } |
229 | if ((err = ferror(projects))) { | 231 | if ((err = ferror(projects))) { |
230 | fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n", | 232 | fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n", |
231 | projectsfile, strerror(err), err); | 233 | projectsfile, strerror(err), err); |
232 | } | 234 | } |
233 | fclose(projects); | 235 | fclose(projects); |