Skip to contentSkip to conversation

handle lower case drive letters on Windows

PATCH Superseded Ben Peart 4 participants 15 messages Jul 11, 2018 – Jul 14, 2018

lore
Share & tools
lore

Ben Peart

author
#0 lore raw

PATCH 1/1 handle lower case drive letters on Windows

Teach test-drop-caches to handle lower case drive letters on Windows.

---

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(-)
t/helper/test-drop-caches.c +1 -1
index d6bcfddf13..37047189c3 100644
@@ -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

Signature · 1 line
2.17.0.gvfs.1.123.g449c066
#1 lore raw
Quoted 2 lines · Ben Peart

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

author
#2 lore raw
Quoted 10 lines

-----Original Message-----
From: Stefan Beller <[email protected]>
Sent: Wednesday, July 11, 2018 1:59 PM
To: Ben Peart <[email protected]>
Cc: git <[email protected]>; Junio C Hamano <[email protected]>
Subject: Re: [PATCH v1] handle lower case drive letters on Windows

Quoted 1 line · Ben Peart
Quoted 7 lines
Quoted 1 line

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.

Quoted 2 lines

Thanks,
Stefan

#3 lore raw
Quoted 18 lines · Ben Peart
Quoted 10 lines

-----Original Message-----
From: Stefan Beller <[email protected]>
Sent: Wednesday, July 11, 2018 1:59 PM
To: Ben Peart <[email protected]>
Cc: git <[email protected]>; Junio C Hamano <[email protected]>
Subject: Re: [PATCH v1] handle lower case drive letters on Windows

Quoted 1 line · Ben Peart
Quoted 7 lines
Quoted 1 line

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?

Quoted 5 lines

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.

author
#4 lore raw
Quoted 41 lines

-----Original Message-----
From: Junio C Hamano <[email protected]> On Behalf Of Junio C Hamano
Sent: Wednesday, July 11, 2018 4:11 PM
To: Ben Peart <[email protected]>
Cc: Stefan Beller <[email protected]>; git <[email protected]>
Subject: Re: [PATCH v1] handle lower case drive letters on Windows

Quoted 18 lines · Ben Peart
Quoted 10 lines

-----Original Message-----
From: Stefan Beller <[email protected]>
Sent: Wednesday, July 11, 2018 1:59 PM
To: Ben Peart <[email protected]>
Cc: git <[email protected]>; Junio C Hamano <[email protected]>
Subject: Re: [PATCH v1] handle lower case drive letters on Windows

Quoted 1 line · Ben Peart
Quoted 7 lines
Quoted 1 line

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?

Quoted 5 lines

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?

Quoted 7 lines

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.

author
#5 lore raw

PATCH v2 1/1 handle lower case drive letters on Windows

In reply to Ben Peart

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.

---

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(-)
t/helper/test-drop-caches.c +1 -1
index d6bcfddf13..37047189c3 100644
@@ -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

Signature · 1 line
2.17.0.gvfs.1.123.g449c066
#6 lore raw
In reply to Ben Peart

Hi Ben,

Quoted 1 line · Ben Peart

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).

t/helper/test-drop-caches.c static int cmd_sync(void) · line 20

Quoted 11 lines
t/helper/test-drop-caches.c +1 -1
index d6bcfddf13..37047189c3 100644
@@ -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

author
#8 lore raw

PATCH v3 1/1 handle lower case drive letters on Windows

In reply to Ben Peart

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.

---

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(-)
t/helper/test-drop-caches.c +2 -2
index d6bcfddf13..f65e301f9d 100644
@@ -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

Signature · 1 line
2.17.0.gvfs.1.123.g449c066
#7 lore raw
In reply to Johannes Schindelin
Quoted 5 lines · Johannes Schindelin

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?

#9 lore raw
In reply to Ben Peart
Quoted 9 lines · Ben Peart

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.

---

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 ;-)

Quoted 45 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(-)
t/helper/test-drop-caches.c +2 -2
index d6bcfddf13..f65e301f9d 100644
@@ -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

author
#10 lore raw
Quoted 15 lines

-----Original Message-----
From: Junio C Hamano <[email protected]> On Behalf Of Junio C Hamano
Sent: Thursday, July 12, 2018 3:13 PM
To: Ben Peart <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v3] handle lower case drive letters on Windows

Quoted 6 lines · Ben Peart

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.

Quoted 8 lines
Quoted 3 lines

---

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"

#11 lore raw
Quoted 19 lines · Ben Peart
Quoted 19 lines

-----Original Message-----
From: Junio C Hamano <[email protected]> On Behalf Of Junio C Hamano
Sent: Thursday, July 12, 2018 3:13 PM
To: Ben Peart <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v3] handle lower case drive letters on Windows

Quoted 9 lines · Ben Peart

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.

---

Quoted 8 lines
Quoted 4 lines

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 ;-)

author
#12 lore raw
Quoted 10 lines
Quoted 3 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?

#13 lore raw
Quoted 5 lines · Ben Peart
Quoted 5 lines
Quoted 3 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"

Quoted 7 lines
Quoted 5 lines

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.

#14 lore raw

Hi Junio,

Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Ben Peart
Quoted 9 lines
Quoted 3 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"

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

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