Skip to contentSkip to conversation

scalar: make enlistment delete to work on all POSIX platforms

PATCH In review Marcel Telka 4 participants 5 messages May 17, 2024 – May 30, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scalar: make enlistment delete to work on all POSIX platforms

The ability to remove the current working directory is not guaranteed by POSIX so it is better to go out of the directory we want to delete on all platforms unconditionally.

---
 scalar.c | 4 ----
 1 file changed, 4 deletions(-)
scalar.c +0 -4
index 7234049a1b..331b91dbdb 100644
@@ -361,16 +361,13 @@ static char *remote_default_branch(const char *url)
 
 static int delete_enlistment(struct strbuf *enlistment)
 {
-#ifdef WIN32
 	struct strbuf parent = STRBUF_INIT;
 	size_t offset;
 	char *path_sep;
-#endif
 
 	if (unregister_dir())
 		return error(_("failed to unregister repository"));
 
-#ifdef WIN32
 	/*
 	 * Change the current directory to one outside of the enlistment so
 	 * that we may delete everything underneath it.
@@ -385,7 +382,6 @@ static int delete_enlistment(struct strbuf *enlistment)
 		return res;
 	}
 	strbuf_release(&parent);
-#endif
 
 	if (have_fsmonitor_support() && stop_fsmonitor_daemon())
 		return error(_("failed to stop the FSMonitor daemon"));
#1 lore raw
Quoted 8 lines · Marcel Telka

The ability to remove the current working directory is not guaranteed by POSIX so it is better to go out of the directory we want to delete on all platforms unconditionally.

---
 scalar.c | 4 ----
 1 file changed, 4 deletions(-)

Let's CC a few folks that had their hands in the delete_enlistment() function over the years for their opinions on this change.

Quoted 29 lines
scalar.c +0 -4
index 7234049a1b..331b91dbdb 100644
@@ -361,16 +361,13 @@ static char *remote_default_branch(const char *url)
 
 static int delete_enlistment(struct strbuf *enlistment)
 {
-#ifdef WIN32
 	struct strbuf parent = STRBUF_INIT;
 	size_t offset;
 	char *path_sep;
-#endif
 
 	if (unregister_dir())
 		return error(_("failed to unregister repository"));
 
-#ifdef WIN32
 	/*
 	 * Change the current directory to one outside of the enlistment so
 	 * that we may delete everything underneath it.
@@ -385,7 +382,6 @@ static int delete_enlistment(struct strbuf *enlistment)
 		return res;
 	}
 	strbuf_release(&parent);
-#endif
 
 	if (have_fsmonitor_support() && stop_fsmonitor_daemon())
 		return error(_("failed to stop the FSMonitor daemon"));
#2 lore raw

Hi,

Quoted 31 lines · Junio C Hamano
Quoted 8 lines · Marcel Telka

The ability to remove the current working directory is not guaranteed by POSIX so it is better to go out of the directory we want to delete on all platforms unconditionally.

---
 scalar.c | 4 ----
 1 file changed, 4 deletions(-)

Let's CC a few folks that had their hands in the delete_enlistment() function over the years for their opinions on this change.

Quoted 17 lines
scalar.c +0 -2
index 7234049a1b..331b91dbdb 100644
@@ -361,16 +361,13 @@ static char *remote_default_branch(const char *url)
 
 static int delete_enlistment(struct strbuf *enlistment)
 {
-#ifdef WIN32
 	struct strbuf parent = STRBUF_INIT;
 	size_t offset;
 	char *path_sep;
-#endif
 
 	if (unregister_dir())
 		return error(_("failed to unregister repository"));
 
Quoted 9 lines

scalar.c static int delete_enlistment(struct strbuf *enlistment) · line 388

Quoted 9 lines
scalar.c +0 -2
-#ifdef WIN32
 	/*
 	 * Change the current directory to one outside of the enlistment so
 	 * that we may delete everything underneath it.
@@ -385,7 +382,6 @@ static int delete_enlistment(struct strbuf *enlistment)
 		return res;
 	}
 	strbuf_release(&parent);
-#endif

Basically, this turns the previously Windows-only logic to chdir("..") into the now-universal logic.

I like it!

Thank you,
Johannes

Quoted 4 lines
Quoted 3 lines
scalar.c +0 -0
 	if (have_fsmonitor_support() && stop_fsmonitor_daemon())
 		return error(_("failed to stop the FSMonitor daemon"));
Reviewed-by on v1 1/1
#3 lore raw
In reply to Marcel Telka
Quoted 32 lines · Marcel Telka

The ability to remove the current working directory is not guaranteed by POSIX so it is better to go out of the directory we want to delete on all platforms unconditionally.

---
 scalar.c | 4 ----
 1 file changed, 4 deletions(-)
scalar.c +0 -3
index 7234049a1b..331b91dbdb 100644
@@ -361,16 +361,13 @@ static char *remote_default_branch(const char *url)
 
 static int delete_enlistment(struct strbuf *enlistment)
 {
-#ifdef WIN32
 	struct strbuf parent = STRBUF_INIT;
 	size_t offset;
 	char *path_sep;
-#endif
 
 	if (unregister_dir())
 		return error(_("failed to unregister repository"));
 
-#ifdef WIN32
 	/*
 	 * Change the current directory to one outside of the enlistment so
 	 * that we may delete everything underneath it.

scalar.c static int delete_enlistment(struct strbuf *enlistment) · line 387

Quoted 7 lines
scalar.c +0 -1
@@ -385,7 +382,6 @@ static int delete_enlistment(struct strbuf *enlistment)
 		return res;
 	}
 	strbuf_release(&parent);
-#endif
 
 	if (have_fsmonitor_support() && stop_fsmonitor_daemon())
 		return error(_("failed to stop the FSMonitor daemon"));

This looks like a straightforward change; none of the formerly protected logic uses anything specific to Windows, and tests still pass on Linux, so this looks good to me.

#4 lore raw
Quoted 5 lines · Josh Steadmon

This looks like a straightforward change; none of the formerly protected logic uses anything specific to Windows, and tests still pass on Linux, so this looks good to me.

Thanks.

With Dscho's Ack we saw earlier, I should have marked the topic for 'next' already, but I was placing a lot of things on back burner. A gentle nudge like this is greatly appreciated.

Will merge to 'next'. Thanks.