Skip to content

Commit

Permalink
cmd_init_db(): when creating directories, handle errors conservatively
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed Jan 6, 2014
1 parent 0be0521 commit f3565c0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions builtin/init-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,14 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
saved = shared_repository;
shared_repository = 0;
switch (safe_create_leading_directories_const(argv[0])) {
case SCLD_OK:
case SCLD_PERMS:
break;
case SCLD_EXISTS:
errno = EEXIST;
/* fallthru */
case SCLD_FAILED:
die_errno(_("cannot mkdir %s"), argv[0]);
break;
default:
die_errno(_("cannot mkdir %s"), argv[0]);
break;
}
shared_repository = saved;
Expand Down

0 comments on commit f3565c0

Please sign in to comment.