Home > database >  Windows two usernames and user paths (normal and corrupted name) referencing to the same user folder
Windows two usernames and user paths (normal and corrupted name) referencing to the same user folder

Time:08-27

I have an issue where both on my Windows machine and a gitlab Windows runner where I have two usernames and valid user path (the "base", and a "corrupted" one). For example, on my local machine:

C:\Users>dir /A

 Directory of C:\Users

10/23/2021  08:51 PM    <DIR>          .
10/23/2021  08:51 PM    <DIR>          ..
10/23/2021  11:27 PM    <SYMLINKD>     All Users [C:\ProgramData]
10/23/2021  11:27 PM    <DIR>          Default
10/23/2021  11:27 PM    <JUNCTION>     Default User [C:\Users\Default]
10/24/2021  12:13 AM               174 desktop.ini
08/22/2022  03:58 PM    <DIR>          J.S.E
10/23/2021  08:35 PM    <DIR>          Public
               1 File(s)            174 bytes
               7 Dir(s)  220,413,632,512 bytes free

but I can do both:

C:\Users>cd C:\Users\J.S.E

C:\Users\J.S.E>

and a "corrupted"

C:\Users>cd C:\Users\JS2896~1.E

C:\Users\JS2896~1.E>

both these paths point to the same folder content, but I can't figure out where this JS2896~1.E comes from.

I noticed this issue while doing some unit testing in python:

I would have a script with a section similar to:

PID_SYNC_FILEPATH = pathlib.Path(tempfile.gettempdir()) / PID_SYNC_FILENAME

That would use that path to create a file. File found at:

C:\\Users\\J.S.E\\AppData\\Local\\Temp\\test_kernel_pid

But when doing checks on the file content during tests (pytest), I would create the path in a similar way but I would then run into (notice the corrupted user name):

 FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\JS2896~1.E\\AppData\\Local\\Temp\\test_kernel_pid'

Basically the issue is: both paths are valid (ex: can be processed with cd in the shell of with pathlib in python), but sometimes are not interpreted as equivalent, causing issues. Anyone knows what is up with that "corrupted username path"

Note: same issue with gitlab Windows runners: two users, runner10 -> C:\\Users\\runner10 and RU4A94~1 -> C:\\Users\\RU4A94~1

CodePudding user response:

Found what seems to be happening:

The "corrupted version", that other people call "short version" is the 8.3 filename that exists before VFAT and the "full path" as you meant it is the "long filename" or LFN. They are interchangeable so long as accessing the file in concern. So J.S.E and JS2896~1.E ("short version") are interpreted in a similar way by the system, but not by my code.

The issue was coming from using tempfile.gettempdir(), that for some reason sometimes gave the long version, sometimes the short version, causing mismatches in my code.

This can be solved by using os.path.realpath

tempfile.gettempdir()
Out[21]: 'C:\\Users\\JS2896~1.E\\AppData\\Local\\Temp'
os.path.realpath(tempfile.gettempdir())
Out[22]: 'C:\\Users\\J.S.E\\AppData\\Local\\Temp'

or with pathlib

pathlib.Path(tempfile.gettempdir())
Out[24]: WindowsPath('C:/Users/JS2896~1.E/AppData/Local/Temp')
pathlib.Path(tempfile.gettempdir()).resolve()
Out[25]: WindowsPath('C:/Users/J.S.E/AppData/Local/Temp')
  • Related