# [PATCH] Solaris 5.8 returns ENOTDIR for inappropriate renames.

2 messages from 2007-01-16 to 2007-01-16. Participants: Jason Riedy, Junio C Hamano.
Thread: https://gitlist.dev/t/6393

## Jason Riedy, 2007-01-16 01:30

Subject: [PATCH] Solaris 5.8 returns ENOTDIR for inappropriate renames.
Message-ID: <17433.1168911059@lotus.CS.Berkeley.EDU>
URL: https://gitlist.dev/e/17433.1168911059%40lotus.CS.Berkeley.EDU

```
The reflog code clears empty directories when rename returns
either EISDIR or ENOTDIR.  Seems to be the only place.

Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu>
---
   Haven't been keeping up with the list, so I apologize if I've
   missed discussions related to these changes.

 refs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/refs.c b/refs.c
index 689ac50..851b573 100644
--- a/refs.c
+++ b/refs.c
@@ -837,7 +837,7 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
 
  retry:
 	if (log && rename(git_path("tmp-renamed-log"), git_path("logs/%s", newref))) {
-		if (errno==EISDIR) {
+		if (errno==EISDIR || errno==ENOTDIR) {
 			if (remove_empty_directories(git_path("logs/%s", newref))) {
 				error("Directory not empty: logs/%s", newref);
 				goto rollback;
-- 
1.5.0.rc1.gf4b6c

```

## Junio C Hamano, 2007-01-16 02:56

Subject: Re: [PATCH] Solaris 5.8 returns ENOTDIR for inappropriate renames.
Message-ID: <7vslebznl5.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vslebznl5.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <17433.1168911059@lotus.CS.Berkeley.EDU>

```
Jason Riedy <ejr@EECS.Berkeley.EDU> writes:

> The reflog code clears empty directories when rename returns
> either EISDIR or ENOTDIR.  Seems to be the only place.
>
> Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu>
> ---
>    Haven't been keeping up with the list, so I apologize if I've
>    missed discussions related to these changes.
>
>  refs.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index 689ac50..851b573 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -837,7 +837,7 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
>  
>   retry:
>  	if (log && rename(git_path("tmp-renamed-log"), git_path("logs/%s", newref))) {
> -		if (errno==EISDIR) {
> +		if (errno==EISDIR || errno==ENOTDIR) {
>  			if (remove_empty_directories(git_path("logs/%s", newref))) {
>  				error("Directory not empty: logs/%s", newref);
>  				goto rollback;

Sorry, I do not understand.

Before this codepath, we have done safe_create_directories() and
should have already errored out if the parent directory of
"logs/$newref" couldn't have been created for whatever reason.
So when this rename fails, we have a file ".git/tmp-renamed-log"
and a directory ".git/logs/foo", and we are trying to rename the
former to ".git/logs/foo/bar".

Now ".git/logs/foo/bar" might already exist as a directory, and
this error path is attempting to catch EISDIR that comes out
from it (and in that case, if there is nothing but empty
directories in the hierarchy under .git/logs/foo/bar, we 
remove them and retry).

Does Solaris give ENOTDIR in such a case?

```
