sha1_file: make sure correct error is propagated
PATCH 1/1 sha1_file: make sure correct error is propagated
From: Sam Vilain <[email protected]>
In the case that a object directory exists, but is not writable, the code path that tries to create it is followed and the returned errno and path that of the directory tried to be created. The resultant error message is confusing.
So, if the mkstemp() fails with EPERM, don't try to create the directory - return straight away.
--- sha1_file.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
sha1_file.c +1 -1
@@ -2231,7 +2231,7 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)memcpy (buffer, filename, dirlen);strcpy (buffer + dirlen,"tmp_obj_XXXXXX" ); fd =mkstemp (buffer); -if (fd <0 && dirlen) { +if (fd <0 && dirlen && (errno !=EPERM )) {/* Make sure the directory exists */ memcpy (buffer, filename, dirlen); buffer[dirlen-1 ] =0 ;
Signature · 1 line
debian.1.5.6.1
Le vendredi 14 novembre 2008, Sam Vilain a écrit :
Quoted 10 lines
From: Sam Vilain <[email protected]>
In the case that a object directory exists, but is not writable, the code path that tries to create it is followed and the returned errno and path that of the directory tried to be created. The resultant error message is confusing.
So, if the
mkstemp()fails with EPERM, don't try to create the directory - return straight away.
Are you sure you didn't mean EACCESS?
Signature · 8 lines
Francis Galiegue ONE2TEAM Ingénieur système Mob : +33 (0) 6 83 87 78 75 Tel : +33 (0) 1 78 94 55 52 [email protected] 40 avenue Raymond Poincaré 75116 Paris
Quoted 3 lines · Francis Galiegue
Quoted 2 lines
So, if the
mkstemp()fails with EPERM, don't try to create the directory - return straight away.Are you sure you didn't mean EACCESS?
Ah, you're right there. Well, maybe this one should be as well:
Subject: sha1_file: accept EACCESS as equivalent to EPERM
This was testing for 'Operation not permitted' rather than any kind of 'Permission Denied' error; prefer EACCESS.
--
Sorry for the inevitable wrapping/whitespace fail :(
sha1_file.c +0 -0
@@ -2231,7 +2231,7 @@ static int create_tmpfile(char *buffer, size_t
bufsiz, const char *filename)
memcpy(buffer, filename, dirlen);
strcpy(buffer + dirlen, "tmp_obj_XXXXXX");
fd = mkstemp(buffer);
- if (fd < 0 && dirlen && (errno != EPERM)) {
+ if (fd < 0 && dirlen && (errno != EACCESS)) {
/* Make sure the directory exists */
memcpy(buffer, filename, dirlen);
buffer[dirlen-1] = 0;
@@ -2257,7 +2257,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
filename = sha1_file_name(sha1);
fd = create_tmpfile(tmpfile, sizeof(tmpfile), filename);
if (fd < 0) {
- if (errno == EPERM)
+ if (errno == EACCESS || errno == EPERM)
return error("insufficient permission for adding an object to
repository database %s\n", get_object_directory());
else
return error("unable to create temporary sha1 filename %s: %s\n",
tmpfile, strerror(errno));
Quoted 14 lines · Sam Vilain
Subject:
sha1_file: accept EACCESS as equivalent to EPERMThis was testing for 'Operation not permitted' rather than any kind of 'Permission Denied' error; prefer EACCESS.
Signed-off-by Sam Vilain <[email protected]>--
Sorry for the inevitable wrapping/whitespace fail :(sha1_file.c +0
-0
sha1_file.c static int create_tmpfile(char *buffer, size_t · line 2235
Quoted 6 lines
sha1_file.c +1
-1@@ -2231,7 +2231,7 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)memcpy (buffer, filename, dirlen);strcpy (buffer + dirlen,"tmp_obj_XXXXXX" ); fd =mkstemp (buffer); -if (fd <0 && dirlen && (errno !=EPERM )) { +if (fd <0 && dirlen && (errno !=EACCESS )) {
Is this accepting the two as equivalents???
Le Friday 14 November 2008 20:05:19 Junio C Hamano, vous avez écrit :
[...]
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +1
-1fd = mkstemp(buffer); - if (fd < 0 && dirlen && (errno != EPERM)) { + if (fd < 0 && dirlen && (errno != EACCESS)) {Is this accepting the two as equivalents???
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Well, looking at mkdir(2), it says:
EPERM The file system containing pathname does not support the
creation of directories.
Hmm, err... git would fail at an earlier point anyway, wouldn't it? Even git init would fail there.
Signature · 8 lines
Francis Galiegue ONE2TEAM Ingénieur système Mob : +33 (0) 6 83 87 78 75 Tel : +33 (0) 1 78 94 55 52 [email protected] 40 avenue Raymond Poincaré 75116 Paris
Quoted 11 lines · Francis Galiegue
Le Friday 14 November 2008 20:05:19 Junio C Hamano, vous avez écrit :
[...]Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +1
-1fd = mkstemp(buffer); - if (fd < 0 && dirlen && (errno != EPERM)) { + if (fd < 0 && dirlen && (errno != EACCESS)) {Is this accepting the two as equivalents???
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines
Well, looking at mkdir(2), it says:
EPERM The file system containing pathname does not support the
creation of directories.Hmm, err... git would fail at an earlier point anyway, wouldn't it? Even git init would fail there.
Not necessarily. .git could be mounted erroneously from via a networked filesystem but without write permissions. Yes, other things would fail then too, but both EPERM and EACCESS are valid and possible return codes.
Signature · 3 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231
Le Friday 14 November 2008 20:50:09 Andreas Ericsson, vous avez écrit :
Quoted 16 lines
Quoted 15 lines · Francis Galiegue
Le Friday 14 November 2008 20:05:19 Junio C Hamano, vous avez écrit :
[...]Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +1
-1fd = mkstemp(buffer); - if (fd < 0 && dirlen && (errno != EPERM)) { + if (fd < 0 && dirlen && (errno != EACCESS)) {Is this accepting the two as equivalents???
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlWell, looking at mkdir(2), it says:
Quoted 8 lines
Quoted 5 lines
EPERM The file system containing pathname does not support the
creation of directories.Hmm, err... git would fail at an earlier point anyway, wouldn't it? Even git init would fail there.
Not necessarily. .git could be mounted erroneously from via a networked filesystem but without write permissions.
In which case EACCESS would be returned anyway. There is quite a difference between EACCESS (Permission denied) and EPERM (operation not permitted).
Basically, my understanding is that mkdir() will only return EPERM if the underlying filesystem can not even CREATE directories on the filesystem. So, unless you are doing very bizarre things with your git repository, I cannot see how you can even trigger an EPERM unless you asked for it.
Quoted 2 lines
Yes, other things would fail
then too, but both EPERM and EACCESS are valid and possible return codes.
And so is ENOSPC, and so is EIO, and so is... It's endless. I think focus should be made on the most common ones, and EACCESS _is_ such one. Others just aren't.
This is why I suggested replacing EPERM with EACCESS in the first place:
EACCESS is by far the most common error code you will get (even root will get that on a read-only filesystem, not EPERM).
Signature · 1 line
fge
Quoted 12 lines · Francis Galiegue
Le Friday 14 November 2008 20:05:19 Junio C Hamano, vous avez écrit :
[...]Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +1
-1fd = mkstemp(buffer); - if (fd < 0 && dirlen && (errno != EPERM)) { + if (fd < 0 && dirlen && (errno != EACCESS)) {Is this accepting the two as equivalents???
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines
Well, looking at mkdir(2), it says:
EPERM The file system containing pathname does not support the
creation of directories.Hmm, err... git would fail at an earlier point anyway, wouldn't it? Even git init would fail there.
Actually, POSIX does not even talk about EPERM for mkdir(2), but that was not my point. The code does something different from what the proposed commit log message talks about. That was what bothered me.
Quoted 3 lines · Junio C Hamano
Actually, POSIX does not even talk about EPERM for mkdir(2), but that was not my point. The code does something different from what the proposed commit log message talks about. That was what bothered me.
My wording was a little terse and confusing. Here's a new one;
Subject: sha1_file.c: resolve confusion EACCESS vs EPERM
EPERM or 'Operation not permitted' is an unlikely error from mkstemp(); test for EACCESS 'Access Denied' instead. Make the special branch which prints the error to the user nicely also understand EACCESS.