cmd_init_db(): when creating directories, handle errors conservatively
safe_create_leading_directories_const() returns a non-zero value on error. The old code at this calling site recognized a couple of particular error values, and treated all other return values as success. Instead, be more conservative: recognize the errors we are interested in, but treat any other nonzero values as failures. This is more robust in case somebody adds another possible return value without telling us. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jan 6, 2014 at 14:45 UTC
f3565c0ca535d3becdcd2266002385709ddfa66c
1 file changed
+4
-3
builtin/init-db.c
+4
-3
@@ -515,13 +515,14 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
515
saved = shared_repository;
516
shared_repository = 0;
517
switch (safe_create_leading_directories_const(argv[0])) {
518
+ case SCLD_OK:
519
+ case SCLD_PERMS:
520
+ break;
521
case SCLD_EXISTS:
522
errno = EEXIST;
523
/* fallthru */
521
- case SCLD_FAILED:
522
- die_errno(_("cannot mkdir %s"), argv[0]);
523
- break;
524
default:
525
+ die_errno(_("cannot mkdir %s"), argv[0]);
526
break;
527
}
528
shared_repository = saved;