git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Ronnie Sahlberg <sahlberg@google.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 02/12] wrapper.c: add a new function unlink_or_msg
Date: Fri, 18 Jul 2014 15:59:21 -0700	[thread overview]
Message-ID: <CAPc5daW_6bVg4B4GHA-HCRL7bzmLAdVOF2xOYa9aOOjze-zTdA@mail.gmail.com> (raw)
In-Reply-To: <xmqqha2el2x5.fsf@gitster.dls.corp.google.com>

Hmm, the primary reason for this seems to be because you are going to handle
multiple refs at a time, some of them might fail to lock due to this
lowest-level
helper to unlink failing, some others may fail to lock due to some other reason,
and the user may want to be able to differentiate various modes of failure.

But even if that were the case, would it be necessary to buffer the messages
like this and give them all at the end? In the transaction code path,
it is likely
that you would be aborting the whole thing at the first failure, no?

I dunno...


On Fri, Jul 18, 2014 at 3:25 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Ronnie Sahlberg <sahlberg@google.com> writes:
>
>> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
>> ---
>>  git-compat-util.h |  6 ++++++
>>  wrapper.c         | 18 ++++++++++++++++++
>>  2 files changed, 24 insertions(+)
>>
>> diff --git a/git-compat-util.h b/git-compat-util.h
>> index b6f03b3..426bc98 100644
>> --- a/git-compat-util.h
>> +++ b/git-compat-util.h
>> @@ -704,12 +704,18 @@ void git_qsort(void *base, size_t nmemb, size_t size,
>>  #endif
>>  #endif
>>
>> +#include "strbuf.h"
>> +
>>  /*
>>   * Preserves errno, prints a message, but gives no warning for ENOENT.
>>   * Always returns the return value of unlink(2).
>>   */
>>  int unlink_or_warn(const char *path);
>>  /*
>> + * Like unlink_or_warn but populates a strbuf
>> + */
>> +int unlink_or_msg(const char *file, struct strbuf *err);
>> +/*
>>   * Likewise for rmdir(2).
>>   */
>>  int rmdir_or_warn(const char *path);
>> diff --git a/wrapper.c b/wrapper.c
>> index 740e193..74a0cc0 100644
>> --- a/wrapper.c
>> +++ b/wrapper.c
>> @@ -438,6 +438,24 @@ static int warn_if_unremovable(const char *op, const char *file, int rc)
>>       return rc;
>>  }
>>
>> +int unlink_or_msg(const char *file, struct strbuf *err)
>> +{
>> +     if (err) {
>> +             int rc = unlink(file);
>> +             int save_errno = errno;
>> +
>> +             if (rc < 0 && errno != ENOENT) {
>> +                     strbuf_addf(err, "unable to unlink %s: %s",
>> +                                 file, strerror(errno));
>> +                     errno = save_errno;
>> +                     return -1;
>> +             }
>> +             return 0;
>> +     }
>> +
>> +     return unlink_or_warn(file);
>> +}
>
> In general, I do not generally like to see messages propagated
> upwards from deeper levels of the callchain to the callers to be
> used later, primarily because that will easily make it harder to
> localize the message-lego.
>
> For this partcular one, shouldn't the caller be doing
>
>         if (unlink(file) && errno != ENOENT) {
>                 ... do its own error message ...
>         }
>
> instead of calling any of the unlink_or_whatever() helper?
>
>
>>  int unlink_or_warn(const char *file)
>>  {
>>       return warn_if_unremovable("unlink", file, unlink(file));

  reply	other threads:[~2014-07-18 22:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16 22:23 [PATCH 00/12] Use ref transactions part 3 Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 01/12] wrapper.c: simplify warn_if_unremovable Ronnie Sahlberg
2014-07-18 22:21   ` Junio C Hamano
2014-07-16 22:23 ` [PATCH 02/12] wrapper.c: add a new function unlink_or_msg Ronnie Sahlberg
2014-07-18 22:25   ` Junio C Hamano
2014-07-18 22:59     ` Junio C Hamano [this message]
2014-07-22 17:42       ` Ronnie Sahlberg
2014-07-22 17:56         ` Junio C Hamano
2014-07-16 22:23 ` [PATCH 03/12] refs.c: add an err argument to delete_ref_loose Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 04/12] refs.c: pass the ref log message to _create/delete/update instead of _commit Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 05/12] refs.c: pass NULL as *flags to read_ref_full Ronnie Sahlberg
2014-07-18 22:31   ` Junio C Hamano
2014-07-22 18:19     ` Ronnie Sahlberg
2014-07-22 21:44       ` Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 06/12] refs.c: move the check for valid refname to lock_ref_sha1_basic Ronnie Sahlberg
2014-07-18 22:37   ` Junio C Hamano
2014-07-16 22:23 ` [PATCH 07/12] refs.c: call lock_ref_sha1_basic directly from commit Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 08/12] refs.c: pass a skip list to name_conflict_fn Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 09/12] refs.c: propagate any errno==ENOTDIR from _commit back to the callers Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 10/12] fetch.c: change s_update_ref to use a ref transaction Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 11/12] refs.c: make write_ref_sha1 static Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 12/12] refs.c: fix handling of badly named refs Ronnie Sahlberg
2014-07-22 20:41   ` Junio C Hamano
2014-07-22 21:30     ` Ronnie Sahlberg
2014-07-22 21:36       ` Ronnie Sahlberg
2014-07-22 21:46       ` Junio C Hamano

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=CAPc5daW_6bVg4B4GHA-HCRL7bzmLAdVOF2xOYa9aOOjze-zTdA@mail.gmail.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=sahlberg@google.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).