equal
deleted
inserted
replaced
249 hg_serve, |
249 hg_serve, |
250 }; |
250 }; |
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 * paranoid wrapper, runs hg executable in server mode. |
281 * paranoid wrapper, runs hg executable in server mode. |
255 */ |
282 */ |
256 static void serve_data(int argc, char **argv) |
283 static void serve_data(int argc, char **argv) |
257 { |
284 { |
258 char *hg_root = HG_ROOT; |
285 char *hg_root = HG_ROOT; |
259 char *repo, *repo_root; |
286 char *repo, *repo_root; |
260 enum cmdline cmd; |
287 enum cmdline cmd; |
261 char *nargv[6]; |
288 char *nargv[6]; |
262 struct stat st; |
|
263 size_t repolen; |
289 size_t repolen; |
264 int i; |
290 int i; |
265 |
291 |
266 /* |
292 /* |
267 * check argv for looking okay. we should be invoked with argv |
293 * check argv for looking okay. we should be invoked with argv |
313 } |
339 } |
314 |
340 |
315 /* only hg init expects no repo. */ |
341 /* only hg init expects no repo. */ |
316 |
342 |
317 if (cmd != hg_init) { |
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 goto badargs; |
349 goto badargs; |
322 } |
350 } |
323 |
351 |
324 /* verify that we really are looking at valid repo. */ |
352 if (valid == 0) { |
325 |
353 valid = validate_repo(repo_root, "store"); |
326 if (stat(abs_path, &st) == -1) { |
354 |
|
355 if (valid == -1) { |
|
356 goto badargs; |
|
357 } |
|
358 } |
|
359 |
|
360 if (valid == 0) { |
327 perror(repo); |
361 perror(repo); |
328 exit(EX_DATAERR); |
362 exit(EX_DATAERR); |
329 } |
363 } |
330 } |
364 } |
331 |
365 |