Show More
@@ -251,6 +251,33 b' enum cmdline {' | |||
|
251 | 251 | |
|
252 | 252 | |
|
253 | 253 | /* |
|
254 | * attempt to verify that a directory is really a hg repo, by testing | |
|
255 | * for the existence of a subdirectory. | |
|
256 | */ | |
|
257 | static int validate_repo(const char *repo_root, const char *subdir) | |
|
258 | { | |
|
259 | char *abs_path; | |
|
260 | struct stat st; | |
|
261 | int ret; | |
|
262 | ||
|
263 | if (asprintf(&abs_path, "%s.hg/%s", repo_root, subdir) == -1) { | |
|
264 | ret = -1; | |
|
265 | goto bail; | |
|
266 | } | |
|
267 | ||
|
268 | /* verify that we really are looking at valid repo. */ | |
|
269 | ||
|
270 | if (stat(abs_path, &st) == -1) { | |
|
271 | ret = 0; | |
|
272 | } else { | |
|
273 | ret = 1; | |
|
274 | } | |
|
275 | ||
|
276 | bail: | |
|
277 | return ret; | |
|
278 | } | |
|
279 | ||
|
280 | /* | |
|
254 | 281 | * paranoid wrapper, runs hg executable in server mode. |
|
255 | 282 | */ |
|
256 | 283 | static void serve_data(int argc, char **argv) |
@@ -259,7 +286,6 b' static void serve_data(int argc, char **' | |||
|
259 | 286 | char *repo, *repo_root; |
|
260 | 287 | enum cmdline cmd; |
|
261 | 288 | char *nargv[6]; |
|
262 | struct stat st; | |
|
263 | 289 | size_t repolen; |
|
264 | 290 | int i; |
|
265 | 291 | |
@@ -315,15 +341,23 b' static void serve_data(int argc, char **' | |||
|
315 | 341 | /* only hg init expects no repo. */ |
|
316 | 342 | |
|
317 | 343 | if (cmd != hg_init) { |
|
318 | char *abs_path; | |
|
344 | int valid; | |
|
319 | 345 | |
|
320 | if (asprintf(&abs_path, "%s.hg/data", repo_root) == -1) { | |
|
346 | valid = validate_repo(repo_root, "data"); | |
|
347 | ||
|
348 | if (valid == -1) { | |
|
321 | 349 | goto badargs; |
|
322 | 350 | } |
|
351 | ||
|
352 | if (valid == 0) { | |
|
353 | valid = validate_repo(repo_root, "store"); | |
|
323 | 354 | |
|
324 | /* verify that we really are looking at valid repo. */ | |
|
325 | ||
|
326 | if (stat(abs_path, &st) == -1) { | |
|
355 | if (valid == -1) { | |
|
356 | goto badargs; | |
|
357 | } | |
|
358 | } | |
|
359 | ||
|
360 | if (valid == 0) { | |
|
327 | 361 | perror(repo); |
|
328 | 362 | exit(EX_DATAERR); |
|
329 | 363 | } |
General Comments 0
You need to be logged in to leave comments.
Login now