From 0be0521b23f46dac586e1b464fafe8b97027b645 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 6 Jan 2014 14:45:25 +0100 Subject: safe_create_leading_directories(): introduce enum for return values Instead of returning magic integer values (which a couple of callers go to the trouble of distinguishing), return values from an enum. Add a docstring. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/init-db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/init-db.c b/builtin/init-db.c index 78aa3872dd..0bc14f3c81 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -515,10 +515,10 @@ 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 -3: + case SCLD_EXISTS: errno = EEXIST; /* fallthru */ - case -1: + case SCLD_FAILED: die_errno(_("cannot mkdir %s"), argv[0]); break; default: -- cgit v1.2.3 From f3565c0ca535d3becdcd2266002385709ddfa66c Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 6 Jan 2014 14:45:26 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/init-db.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/init-db.c b/builtin/init-db.c index 0bc14f3c81..ceeb138ba8 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -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; -- cgit v1.2.3