All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Karl Moskowski <kmoskowski@me.com>,
	Jeff King <peff@peff.net>, Mike Hommey <mh@glandium.org>,
	David Turner <dturner@twopensource.com>,
	Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH v2 02/20] safe_create_leading_directories(): set errno on SCLD_EXISTS
Date: Thu, 25 Feb 2016 14:16:01 +0100	[thread overview]
Message-ID: <bf790258cb69fc63fd6ebaddd249face1ff2bdf6.1456405698.git.mhagger@alum.mit.edu> (raw)
In-Reply-To: <cover.1456405698.git.mhagger@alum.mit.edu>

The exit path for SCLD_EXISTS wasn't setting errno, which some callers
use to generate error messages for the user. Fix the problem and
document that the function sets errno correctly to help avoid similar
regressions in the future.

While we're at it, document the difference between
safe_create_leading_directories() and
safe_create_leading_directories_const().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 cache.h     | 10 ++++++++--
 sha1_file.c |  4 +++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 26640b4..7d3f80c 100644
--- a/cache.h
+++ b/cache.h
@@ -950,8 +950,9 @@ int adjust_shared_perm(const char *path);
 
 /*
  * Create the directory containing the named path, using care to be
- * somewhat safe against races.  Return one of the scld_error values
- * to indicate success/failure.
+ * somewhat safe against races. Return one of the scld_error values to
+ * indicate success/failure. On error, set errno to describe the
+ * problem.
  *
  * SCLD_VANISHED indicates that one of the ancestor directories of the
  * path existed at one point during the function call and then
@@ -959,6 +960,11 @@ int adjust_shared_perm(const char *path);
  * directory while we were working.  To be robust against this kind of
  * race, callers might want to try invoking the function again when it
  * returns SCLD_VANISHED.
+ *
+ * The non _const version of this function temporarily modifies its
+ * path parameter while it is working but restores it before exiting.
+ * The _const version does not modify path (at the cost of having to
+ * make a temporary scratch copy).
  */
 enum scld_error {
 	SCLD_OK = 0,
diff --git a/sha1_file.c b/sha1_file.c
index 568120e..94c6779 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -135,8 +135,10 @@ enum scld_error safe_create_leading_directories(char *path)
 		*slash = '\0';
 		if (!stat(path, &st)) {
 			/* path exists */
-			if (!S_ISDIR(st.st_mode))
+			if (!S_ISDIR(st.st_mode)) {
+				errno = ENOTDIR;
 				ret = SCLD_EXISTS;
+			}
 		} else if (mkdir(path, 0777)) {
 			if (errno == EEXIST &&
 			    !stat(path, &st) && S_ISDIR(st.st_mode))
-- 
2.7.0

  parent reply	other threads:[~2016-02-25 13:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-25 13:15 [PATCH v2 00/20] Delete directories left empty after ref deletion Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 01/20] safe_create_leading_directories_const(): preserve errno Michael Haggerty
2016-02-25 13:16 ` Michael Haggerty [this message]
2016-02-25 13:16 ` [PATCH v2 03/20] raceproof_create_file(): new function Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 04/20] lock_ref_sha1_basic(): use raceproof_create_file() Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 05/20] rename_tmp_log(): " Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 06/20] rename_tmp_log(): improve error reporting Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 07/20] log_ref_setup(): separate code for create vs non-create Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 08/20] log_ref_setup(): improve robustness against races Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 09/20] log_ref_setup(): pass the open file descriptor back to the caller Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 10/20] log_ref_write_1(): don't depend on logfile Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 11/20] log_ref_setup(): manage the name of the reflog file internally Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 12/20] log_ref_write_1(): inline function Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 13/20] try_remove_empty_parents(): rename parameter "name" -> "refname" Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 14/20] try_remove_empty_parents(): don't trash argument contents Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 15/20] try_remove_empty_parents(): don't accommodate consecutive slashes Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 16/20] t5505: use "for-each-ref" to test for the non-existence of references Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 17/20] delete_ref_loose(): derive loose reference path from lock Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 18/20] delete_ref_loose(): inline function Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 19/20] try_remove_empty_parents(): teach to remove parents of reflogs, too Michael Haggerty
2016-02-25 13:16 ` [PATCH v2 20/20] ref_transaction_commit(): clean up empty directories Michael Haggerty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf790258cb69fc63fd6ebaddd249face1ff2bdf6.1456405698.git.mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=dturner@twopensource.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kmoskowski@me.com \
    --cc=mh@glandium.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.