threads / patch / 48863

patchhandle lower case drive letters on Windows

Subject: [PATCH v1] handle lower case drive letters on Windows

## tl;dr

15 messages between Jul 11, 2018 and Jul 14, 2018. Diffs are folded; open one to read it.

replies: 14people: 4as markdown or json

Ben Peart· Jul 11, 2018, 17:54 UTC · lore
Teach test-drop-caches to handle lower case drive letters on Windows.
Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
---
Notes:
    Base Ref: master
    Web-Diff: https://github.com/benpeart/git/commit/55b815ee73
    Checkout: git fetch https://github.com/benpeart/git drop-caches-v1 && git checkout 55b815ee73
 t/helper/test-drop-caches.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to t/helper/test-drop-caches.c +1 −1
diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
index d6bcfddf13..37047189c3 100644
--- a/t/helper/test-drop-caches.c
+++ b/t/helper/test-drop-caches.c
@@ -16,7 +16,7 @@ static int cmd_sync(void)
 	if ((0 == dwRet) || (dwRet > MAX_PATH))
 		return error("Error getting current directory");
 
-	if ((Buffer[0] < 'A') || (Buffer[0] > 'Z'))
+	if ((toupper(Buffer[0]) < 'A') || (toupper(Buffer[0]) > 'Z'))
 		return error("Invalid drive letter '%c'", Buffer[0]);
 
 	szVolumeAccessPath[4] = Buffer[0];

base-commit: e3331758f12da22f4103eec7efe1b5304a9be5e9
-- 
2.17.0.gvfs.1.123.g449c066
Stefan Beller· Jul 11, 2018, 17:59 UTC · re: Ben Peart · lore

Re: [PATCH v1] handle lower case drive letters on Windows

On Wed, Jul 11, 2018 at 10:54 AM Ben Peart <Ben.Peart@microsoft.com> wrote:
>
> Teach test-drop-caches to handle lower case drive letters on Windows.

As someone not quite familiar with Windows (and using Git there), is this addressing a user visible issue, or a developer visible issue? (It looks to me as the latter as it touches test code). In which way does it improve the life of a developer?

Thanks, Stefan

Ben Peart· Jul 11, 2018, 19:07 UTC · re: Stefan Beller · lore

RE: [PATCH v1] handle lower case drive letters on Windows

Show 17 quoted lines
> -----Original Message-----
> From: Stefan Beller <sbeller@google.com>
> Sent: Wednesday, July 11, 2018 1:59 PM
> To: Ben Peart <Ben.Peart@microsoft.com>
> Cc: git <git@vger.kernel.org>; Junio C Hamano <gitster@pobox.com>
> Subject: Re: [PATCH v1] handle lower case drive letters on Windows
> 
> On Wed, Jul 11, 2018 at 10:54 AM Ben Peart <Ben.Peart@microsoft.com>
> wrote:
> >
> > Teach test-drop-caches to handle lower case drive letters on Windows.
> 
> As someone not quite familiar with Windows (and using Git there),
> is this addressing a user visible issue, or a developer visible issue?
> (It looks to me as the latter as it touches test code). In which way
> does it improve the life of a developer?
> 

It is a developer visible issue. On Windows, file names (including drive letters) are case insensitive. This patch improves the life of a Windows developer by making drive letters case insensitive for the test-drop-caches test application as well. Without this patch "test-drop-caches e" will fail with an error "Invalid drive letter 'e'" instead of succeeding as expected.

> Thanks,
> Stefan
Junio C Hamano· Jul 11, 2018, 20:11 UTC · re: Ben Peart · lore

Re: [PATCH v1] handle lower case drive letters on Windows

Ben Peart <Ben.Peart@microsoft.com> writes:
Show 23 quoted lines
>> -----Original Message-----
>> From: Stefan Beller <sbeller@google.com>
>> Sent: Wednesday, July 11, 2018 1:59 PM
>> To: Ben Peart <Ben.Peart@microsoft.com>
>> Cc: git <git@vger.kernel.org>; Junio C Hamano <gitster@pobox.com>
>> Subject: Re: [PATCH v1] handle lower case drive letters on Windows
>> 
>> On Wed, Jul 11, 2018 at 10:54 AM Ben Peart <Ben.Peart@microsoft.com>
>> wrote:
>> >
>> > Teach test-drop-caches to handle lower case drive letters on Windows.
>> 
>> As someone not quite familiar with Windows (and using Git there),
>> is this addressing a user visible issue, or a developer visible issue?
>> (It looks to me as the latter as it touches test code). In which way
>> does it improve the life of a developer?
>> 
>
> It is a developer visible issue.  On Windows, file names (including drive
> letters) are case insensitive.  This patch improves the life of a Windows
> developer by making drive letters case insensitive for the test-drop-caches
> test application as well.  Without this patch "test-drop-caches e" will fail
> with an error "Invalid drive letter 'e'" instead of succeeding as expected.

I think one point of the original question was if it is common for a developer to say "test-drop-caches e" from the command line, or the helper is run solely by being written in some numbered test script directly under t/. In the latter case, it would be reasonable to expect and insist the scripts to use the more canonical form, even if the platform is case insensitive (assuming E: is more canonical than e:, that is) no?

In any case, a larger point is that it would help other people who read the patch and "git log" output, if the answer you gave Stefan in the message I am responding to, and another one that you may give me in a response to this message, were in the proposed log message in the patch.

Thanks.
Ben Peart· Jul 11, 2018, 21:30 UTC · re: Junio C Hamano · lore

RE: [PATCH v1] handle lower case drive letters on Windows

Show 48 quoted lines
> -----Original Message-----
> From: Junio C Hamano <jch2355@gmail.com> On Behalf Of Junio C Hamano
> Sent: Wednesday, July 11, 2018 4:11 PM
> To: Ben Peart <Ben.Peart@microsoft.com>
> Cc: Stefan Beller <sbeller@google.com>; git <git@vger.kernel.org>
> Subject: Re: [PATCH v1] handle lower case drive letters on Windows
> 
> Ben Peart <Ben.Peart@microsoft.com> writes:
> 
> >> -----Original Message-----
> >> From: Stefan Beller <sbeller@google.com>
> >> Sent: Wednesday, July 11, 2018 1:59 PM
> >> To: Ben Peart <Ben.Peart@microsoft.com>
> >> Cc: git <git@vger.kernel.org>; Junio C Hamano <gitster@pobox.com>
> >> Subject: Re: [PATCH v1] handle lower case drive letters on Windows
> >>
> >> On Wed, Jul 11, 2018 at 10:54 AM Ben Peart <Ben.Peart@microsoft.com>
> >> wrote:
> >> >
> >> > Teach test-drop-caches to handle lower case drive letters on Windows.
> >>
> >> As someone not quite familiar with Windows (and using Git there),
> >> is this addressing a user visible issue, or a developer visible issue?
> >> (It looks to me as the latter as it touches test code). In which way
> >> does it improve the life of a developer?
> >>
> >
> > It is a developer visible issue.  On Windows, file names (including drive
> > letters) are case insensitive.  This patch improves the life of a Windows
> > developer by making drive letters case insensitive for the test-drop-caches
> > test application as well.  Without this patch "test-drop-caches e" will fail
> > with an error "Invalid drive letter 'e'" instead of succeeding as expected.
> 
> I think one point of the original question was if it is common for a
> developer to say "test-drop-caches e" from the command line, or the
> helper is run solely by being written in some numbered test script
> directly under t/.  In the latter case, it would be reasonable to
> expect and insist the scripts to use the more canonical form, even
> if the platform is case insensitive (assuming E: is more canonical
> than e:, that is) no?
> 
> In any case, a larger point is that it would help other people who
> read the patch and "git log" output, if the answer you gave Stefan
> in the message I am responding to, and another one that you may give
> me in a response to this message, were in the proposed log message
> in the patch.
> 
> Thanks.

I apologize. My memory had faded as to the scenario that caused the issue and my earlier response was incorrect.

Some months ago I ran into a situation where GetCurrentDirectory returned a lower case drive letter which caused test-drop-caches to fail. While most tools _do_ upper case the drive letter before calling SetCurrentDirectory, it isn't anything that is enforced so you _can_ get a lower case drive letter from GetCurrentDirectory and we should handle it properly.

At the time, I simply patched my local copy to properly handle that case and the patch has been sitting in my "todo" backlog for a while now. I'll submit a V2 with a better commit message.

Ben Peart· Jul 11, 2018, 21:41 UTC · re: Ben Peart · lore

[PATCH v2] handle lower case drive letters on Windows

On Windows, if a tool calls SetCurrentDirectory with a lower case drive letter, the subsequent call to GetCurrentDirectory will return the same lower case drive letter. If that happens, test-drop-caches will error out as it does not correctly to handle lower case drive letters.

Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
---
Notes:
    Base Ref: master
    Web-Diff: https://github.com/benpeart/git/commit/b497c111a7
    Checkout: git fetch https://github.com/benpeart/git drop-caches-v2 && git checkout b497c111a7
    
    ### Interdiff (v1..v2):
    
    ### Patches
 t/helper/test-drop-caches.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to t/helper/test-drop-caches.c +1 −1
diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
index d6bcfddf13..37047189c3 100644
--- a/t/helper/test-drop-caches.c
+++ b/t/helper/test-drop-caches.c
@@ -16,7 +16,7 @@ static int cmd_sync(void)
 	if ((0 == dwRet) || (dwRet > MAX_PATH))
 		return error("Error getting current directory");
 
-	if ((Buffer[0] < 'A') || (Buffer[0] > 'Z'))
+	if ((toupper(Buffer[0]) < 'A') || (toupper(Buffer[0]) > 'Z'))
 		return error("Invalid drive letter '%c'", Buffer[0]);
 
 	szVolumeAccessPath[4] = Buffer[0];

base-commit: e3331758f12da22f4103eec7efe1b5304a9be5e9
-- 
2.17.0.gvfs.1.123.g449c066
Johannes Schindelin· Jul 12, 2018, 13:59 UTC · re: Ben Peart · lore

Re: [PATCH v1] handle lower case drive letters on Windows

Hi Ben,
On Wed, 11 Jul 2018, Ben Peart wrote:
> Teach test-drop-caches to handle lower case drive letters on Windows.

Maybe mention that you can trigger this by using a lower case drive letter in Powershell (CMD normalizes your path, Powershell does not).

Show 11 quoted lines
> diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
> index d6bcfddf13..37047189c3 100644
> --- a/t/helper/test-drop-caches.c
> +++ b/t/helper/test-drop-caches.c
> @@ -16,7 +16,7 @@ static int cmd_sync(void)
>  	if ((0 == dwRet) || (dwRet > MAX_PATH))
>  		return error("Error getting current directory");
>  
> -	if ((Buffer[0] < 'A') || (Buffer[0] > 'Z'))
> +	if ((toupper(Buffer[0]) < 'A') || (toupper(Buffer[0]) > 'Z'))
>  		return error("Invalid drive letter '%c'", Buffer[0]);

This is a rather incomplete test, as it does not even test for the colon after the drive letter.

But I guess the more common case where this code path triggers the error is when your current directory is a UNC path to a file share (again, only possible in Powershell, CMD does not let you do that unless you play serious tricks).

So maybe a much better idea is to use our `has_dos_drive_prefix()` function:

	if (!has_dos_drive_prefix(Buffer))
		return error("'%s': invalid drive letter", Buffer);

Ciao, Johannes

Junio C Hamano· Jul 12, 2018, 16:33 UTC · re: Johannes Schindelin · lore

Re: [PATCH v1] handle lower case drive letters on Windows

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 5 quoted lines
> So maybe a much better idea is to use our `has_dos_drive_prefix()`
> function:
>
> 	if (!has_dos_drive_prefix(Buffer))
> 		return error("'%s': invalid drive letter", Buffer);
"'%s': path without valid drive prefix", you mean?
Ben Peart· Jul 12, 2018, 15:44 UTC · re: Ben Peart · lore

[PATCH v3] handle lower case drive letters on Windows

On Windows, if a tool calls SetCurrentDirectory with a lower case drive letter, the subsequent call to GetCurrentDirectory will return the same lower case drive letter. Powershell, for example, does not normalize the path. If that happens, test-drop-caches will error out as it does not correctly to handle lower case drive letters.

Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
---
Notes:
    Base Ref: master
    Web-Diff: https://github.com/benpeart/git/commit/1ff8de1b6c
    Checkout: git fetch https://github.com/benpeart/git drop-caches-v3 && git checkout 1ff8de1b6c
    
    ### Interdiff (v2..v3):
    
    diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
    index 37047189c3..f65e301f9d 100644
    --- a/t/helper/test-drop-caches.c
    +++ b/t/helper/test-drop-caches.c
    @@ -16,8 +16,8 @@ static int cmd_sync(void)
     	if ((0 == dwRet) || (dwRet > MAX_PATH))
     		return error("Error getting current directory");
    
    -	if ((toupper(Buffer[0]) < 'A') || (toupper(Buffer[0]) > 'Z'))
    -		return error("Invalid drive letter '%c'", Buffer[0]);
    +	if (!has_dos_drive_prefix(Buffer))
    +		return error("'%s': invalid drive letter", Buffer);
    
     	szVolumeAccessPath[4] = Buffer[0];
     	hVolWrite = CreateFile(szVolumeAccessPath, GENERIC_READ | GENERIC_WRITE,
    
    ### Patches
 t/helper/test-drop-caches.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to t/helper/test-drop-caches.c +2 −2
diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
index d6bcfddf13..f65e301f9d 100644
--- a/t/helper/test-drop-caches.c
+++ b/t/helper/test-drop-caches.c
@@ -16,8 +16,8 @@ static int cmd_sync(void)
 	if ((0 == dwRet) || (dwRet > MAX_PATH))
 		return error("Error getting current directory");
 
-	if ((Buffer[0] < 'A') || (Buffer[0] > 'Z'))
-		return error("Invalid drive letter '%c'", Buffer[0]);
+	if (!has_dos_drive_prefix(Buffer))
+		return error("'%s': invalid drive letter", Buffer);
 
 	szVolumeAccessPath[4] = Buffer[0];
 	hVolWrite = CreateFile(szVolumeAccessPath, GENERIC_READ | GENERIC_WRITE,

base-commit: e3331758f12da22f4103eec7efe1b5304a9be5e9
-- 
2.17.0.gvfs.1.123.g449c066
Junio C Hamano· Jul 12, 2018, 19:12 UTC · re: Ben Peart · lore

Re: [PATCH v3] handle lower case drive letters on Windows

Ben Peart <Ben.Peart@microsoft.com> writes:
Show 9 quoted lines
> On Windows, if a tool calls SetCurrentDirectory with a lower case drive
> letter, the subsequent call to GetCurrentDirectory will return the same
> lower case drive letter. Powershell, for example, does not normalize the
> path. If that happens, test-drop-caches will error out as it does not
> correctly to handle lower case drive letters.
>
> Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
> ---

Thanks. Will replace, even though showing the whole Buffer (I am guessing it is the equivalent of result from getcwd(3) call) and complaining about drive "letter" feels a bit strange ;-)

Show 45 quoted lines
> Notes:
>     Base Ref: master
>     Web-Diff: https://github.com/benpeart/git/commit/1ff8de1b6c
>     Checkout: git fetch https://github.com/benpeart/git drop-caches-v3 && git checkout 1ff8de1b6c
>     
>     ### Interdiff (v2..v3):
>     
>     diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
>     index 37047189c3..f65e301f9d 100644
>     --- a/t/helper/test-drop-caches.c
>     +++ b/t/helper/test-drop-caches.c
>     @@ -16,8 +16,8 @@ static int cmd_sync(void)
>      	if ((0 == dwRet) || (dwRet > MAX_PATH))
>      		return error("Error getting current directory");
>     
>     -	if ((toupper(Buffer[0]) < 'A') || (toupper(Buffer[0]) > 'Z'))
>     -		return error("Invalid drive letter '%c'", Buffer[0]);
>     +	if (!has_dos_drive_prefix(Buffer))
>     +		return error("'%s': invalid drive letter", Buffer);
>     
>      	szVolumeAccessPath[4] = Buffer[0];
>      	hVolWrite = CreateFile(szVolumeAccessPath, GENERIC_READ | GENERIC_WRITE,
>     
>     ### Patches
>
>  t/helper/test-drop-caches.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/t/helper/test-drop-caches.c b/t/helper/test-drop-caches.c
> index d6bcfddf13..f65e301f9d 100644
> --- a/t/helper/test-drop-caches.c
> +++ b/t/helper/test-drop-caches.c
> @@ -16,8 +16,8 @@ static int cmd_sync(void)
>  	if ((0 == dwRet) || (dwRet > MAX_PATH))
>  		return error("Error getting current directory");
>  
> -	if ((Buffer[0] < 'A') || (Buffer[0] > 'Z'))
> -		return error("Invalid drive letter '%c'", Buffer[0]);
> +	if (!has_dos_drive_prefix(Buffer))
> +		return error("'%s': invalid drive letter", Buffer);
>  
>  	szVolumeAccessPath[4] = Buffer[0];
>  	hVolWrite = CreateFile(szVolumeAccessPath, GENERIC_READ | GENERIC_WRITE,
>
> base-commit: e3331758f12da22f4103eec7efe1b5304a9be5e9
Ben Peart· Jul 12, 2018, 19:23 UTC · re: Junio C Hamano · lore

RE: [PATCH v3] handle lower case drive letters on Windows

Show 23 quoted lines
> -----Original Message-----
> From: Junio C Hamano <jch2355@gmail.com> On Behalf Of Junio C Hamano
> Sent: Thursday, July 12, 2018 3:13 PM
> To: Ben Peart <Ben.Peart@microsoft.com>
> Cc: git@vger.kernel.org; sbeller@google.com; johannes.schindelin@gmx.de
> Subject: Re: [PATCH v3] handle lower case drive letters on Windows
> 
> Ben Peart <Ben.Peart@microsoft.com> writes:
> 
> > On Windows, if a tool calls SetCurrentDirectory with a lower case drive
> > letter, the subsequent call to GetCurrentDirectory will return the same
> > lower case drive letter. Powershell, for example, does not normalize the
> > path. If that happens, test-drop-caches will error out as it does not
> > correctly to handle lower case drive letters.
> >
> > Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
> > ---
> 
> Thanks.  Will replace, even though showing the whole Buffer (I am
> guessing it is the equivalent of result from getcwd(3) call) and
> complaining about drive "letter" feels a bit strange ;-)
> 

Thanks. I thought it was strange as well until I realized you only see the error message if there _isn't_ a valid drive letter so seeing the entire path makes sense as it will likely be something like "\\server\volume\directory"

Junio C Hamano· Jul 12, 2018, 19:53 UTC · re: Ben Peart · lore

Re: [PATCH v3] handle lower case drive letters on Windows

Ben Peart <Ben.Peart@microsoft.com> writes:
Show 27 quoted lines
>> -----Original Message-----
>> From: Junio C Hamano <jch2355@gmail.com> On Behalf Of Junio C Hamano
>> Sent: Thursday, July 12, 2018 3:13 PM
>> To: Ben Peart <Ben.Peart@microsoft.com>
>> Cc: git@vger.kernel.org; sbeller@google.com; johannes.schindelin@gmx.de
>> Subject: Re: [PATCH v3] handle lower case drive letters on Windows
>> 
>> Ben Peart <Ben.Peart@microsoft.com> writes:
>> 
>> > On Windows, if a tool calls SetCurrentDirectory with a lower case drive
>> > letter, the subsequent call to GetCurrentDirectory will return the same
>> > lower case drive letter. Powershell, for example, does not normalize the
>> > path. If that happens, test-drop-caches will error out as it does not
>> > correctly to handle lower case drive letters.
>> >
>> > Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
>> > Signed-off-by: Ben Peart <Ben.Peart@microsoft.com>
>> > ---
>> 
>> Thanks.  Will replace, even though showing the whole Buffer (I am
>> guessing it is the equivalent of result from getcwd(3) call) and
>> complaining about drive "letter" feels a bit strange ;-)
>> 
>
> Thanks.  I thought it was strange as well until I realized you only see the
> error message if there _isn't_ a valid drive letter so seeing the entire
> path makes sense as it will likely be something like "\\server\volume\directory"
Yup, that is why I thought Dscho meant to say something like
	"'%s': path without valid drive prefix"
in my response ;-)
Ben Peart· Jul 12, 2018, 20:09 UTC · re: Junio C Hamano · lore

RE: [PATCH v3] handle lower case drive letters on Windows

Show 10 quoted lines
> > Thanks.  I thought it was strange as well until I realized you only
> > see the error message if there _isn't_ a valid drive letter so seeing
> > the entire path makes sense as it will likely be something like
> "\\server\volume\directory"
> 
> Yup, that is why I thought Dscho meant to say something like
> 
> 	"'%s': path without valid drive prefix"
> 
> in my response ;-)
I'm fine with that - want me to leave it alone, spin a V4 or have you tweak it?
Junio C Hamano· Jul 12, 2018, 20:34 UTC · re: Ben Peart · lore

Re: [PATCH v3] handle lower case drive letters on Windows

Ben Peart <Ben.Peart@microsoft.com> writes:
Show 12 quoted lines
>> > Thanks.  I thought it was strange as well until I realized you only
>> > see the error message if there _isn't_ a valid drive letter so seeing
>> > the entire path makes sense as it will likely be something like
>> "\\server\volume\directory"
>> 
>> Yup, that is why I thought Dscho meant to say something like
>> 
>> 	"'%s': path without valid drive prefix"
>> 
>> in my response ;-)
>
> I'm fine with that - want me to leave it alone, spin a V4 or have you tweak it?

That's "helped-by Dscho" patch, so I'd leave it to him by queuing v3 overnight and wait to deal with the final decision by the weekend ;-) That way, I do not have to make a decision on anything Windows related.

Johannes Schindelin· Jul 14, 2018, 22:15 UTC · re: Junio C Hamano · lore

Re: [PATCH v3] handle lower case drive letters on Windows

Hi Junio,
On Thu, 12 Jul 2018, Junio C Hamano wrote:
Show 19 quoted lines
> Ben Peart <Ben.Peart@microsoft.com> writes:
> 
> >> > Thanks.  I thought it was strange as well until I realized you only
> >> > see the error message if there _isn't_ a valid drive letter so seeing
> >> > the entire path makes sense as it will likely be something like
> >> "\\server\volume\directory"
> >> 
> >> Yup, that is why I thought Dscho meant to say something like
> >> 
> >> 	"'%s': path without valid drive prefix"
> >> 
> >> in my response ;-)
> >
> > I'm fine with that - want me to leave it alone, spin a V4 or have you tweak it?
> 
> That's "helped-by Dscho" patch, so I'd leave it to him by queuing v3
> overnight and wait to deal with the final decision by the weekend
> ;-) That way, I do not have to make a decision on anything Windows
> related.
The tweaked error message is fine by me.

Ciao, Dscho

← back to recent threads