[9.21a] Cd doesn't normalize paths

Please report only one bug per message!

Moderators: white, Hacker, petermad, Stefan2

User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

[9.21a] Cd doesn't normalize paths

Post by *MVV »

When I do cd D:\\DirA\\DirB\\DirC\\DirD, TC opens dir and shows this non-normalized path in path bar, and also passes it to plugins etc, causing errors in plugins. E.g. when I press F3 in a file after such cd, it applies NoDirQuickView plugin for file (but this plugin is only for folders).

Please make TC normalize paths passed to cd command or command line or corresponding WM_COPYDATA message.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [9.21a] Cd doesn't normalize paths

Post by *ghisler(Author) »

Why? Windows isn't case sensitive.
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: [9.21a] Cd doesn't normalize paths

Post by *MVV »

I mean that you should normalize (canonicalize) external paths (that come to cd command etc) by removing duplicate backslashes or stuff like \.\ or \..\, just like GetFullPathName function does before changing dir or displaying them in path bars:

Code: Select all

wchar_t buf[260];
GetFullPathName(L"D:\\\\\\dir1\\\\dir2\\\\..\\\\dir2_again\\.\\dir3", MAX_PATH, buf, nullptr);
// --> L"D:\\dir1\\dir2_again\\dir3"
GetFullPathName(L"\\\\comp11\\D\\\\\\dir1\\\\dir2\\\\..\\\\dir2_again\\.\\dir3", MAX_PATH, buf, nullptr);
// --> L"\\\\comp11\\D\\dir1\\dir2_again\\dir3"
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [9.21a] Cd doesn't normalize paths

Post by *ghisler(Author) »

If I remember correctly, GetFullPathName only fixes the last name part after the last backslash, but not the other parts of the path.
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: [9.21a] Cd doesn't normalize paths

Post by *MVV »

As you can see, it fixes overall path, so it may be quite useful here. It doesn't check if final path exists so it only canonicalizes it. It would be very nice to see this fixed because sometimes I need to copy paths from IDEs where slashes in strings are usually doubled.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: [9.21a] Cd doesn't normalize paths

Post by *MVV »

Maybe it is time to fix this? Today I wondered why no file properties shown on Alt+Enter and why context menu looks so trimmed, then I've noticed an extra backslash in the path.

Very often such problems are from concatenating environment variables with trailing backslashes with some subpaths. Such paths are supported by OS and shouldn't cause any problems in TC too. You can either normalize paths like CMD.EXE does (try to execute cd /D %SystemRoot%\\System32 command, you'll see normalized current path without extra backslash) or just properly handle non-normalized path (i.e. extra backslashes shouldn't affect on TC/plugins functionality). But current behaviour is buggy: TC shows valid folder contents but some functions are broken.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [9.21a] Cd doesn't normalize paths

Post by *ghisler(Author) »

Removing duplicate slashes is easy, so I will add that. However, I will not normalize upper-/lowercase, because Windows is case insensitive.
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: [9.21a] Cd doesn't normalize paths

Post by *MVV »

Thanks, I think you can juse use GetFullPathName, it fixes extra backslashes or references to . or .., but keeps cases.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [9.21a] Cd doesn't normalize paths

Post by *ghisler(Author) »

I'm already remoning \..\ and \.\ etc, all I need to do is remove \\ and //.
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: [9.21a] Cd doesn't normalize paths

Post by *MVV »

BTW I found a real problem caused by this issue. On my corporate machine I have TEMP set to C:\temp\%USERNAME%\ and there is something (probably security setting) that appends a numeric subfolder name, and it appends it with extra backslash, resulting in TEMP variable value like C:\temp\%USERNAME%\\107. This causes TC to fail when I try viewing or extracting files fron a nested archive because it gets a doubled backslash in its path when it is extracted by TC to the temporary folder and opened.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [9.21a] Cd doesn't normalize paths

Post by *ghisler(Author) »

Could you explain in more detail what happens? Does %USERNAME% contain something like MVV\\107 or do I misunderstand that?
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: [9.21a] Cd doesn't normalize paths

Post by *MVV »

No, USERNAME contains just account name as it should, but TEMP expands to a path with doubled backslash in it. And since TC uses temp folder for its temporary files, these files have paths with this doubled backslash.

Just tried it with TC 11.01, problem still exists.
Steps to reproduce:
1. Open cmd.exe and set TEMP and TMP to a path with doubled backslash, in my case it is C:\temp\USERNA~1\\7.
2. Start TC from that console to make it inherit this non-normalized path to temp folder.
3. Open a .tar.gz file, then enter .tar in it, try viewing any file in .tar.
4. Even for a .txt file (that doesn't require any plugins) I get "Access denied" error with path to that file in temp folder with non-normalized path.
5. Without closing error message on step 4 I see that temp folder only contains .tar file, but there is no file that I tried to view.
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: [9.21a] Cd doesn't normalize paths

Post by *petermad »

2MVV
On my corporate machine I have TEMP set to C:\temp\%USERNAME%\
Can't you just set temp to C:\temp\%USERNAME% instead of C:\temp\%USERNAME%\ - or is that out of your hands on that machine?

Normally environment variables for paths are not set with a trailing backslash.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: [9.21a] Cd doesn't normalize paths

Post by *MVV »

As for me, I can just define path to TC temp dir in Autorun's cfg file, but I think that this little TC issue should be resolved since it may broke many TC features in case of incorrectly configured environment, and it is pretty easy to resolve. Though non-normalized paths in Windows shouldn't cause any errors at all, any system API function accepts such paths w/o any troubles, so TC should also live fine with them.
JOUBE
Power Member
Power Member
Posts: 1448
Joined: 2004-07-08, 08:58 UTC

Re: [9.21a] Cd doesn't normalize paths

Post by *JOUBE »

MVV wrote: 2023-12-14, 09:57 UTC... in case of incorrectly configured environment ...
So, no support for this suggestion. -1
Post Reply