cygpath and unc paths
Federico Kircheis
federico@kircheis.it
Mon Dec 9 13:48:01 GMT 2024
On 09/12/2024 14.17, Corinna Vinschen via Cygwin wrote:
> On Dec 9 13:47, Federico Kircheis via Cygwin wrote:
>> On 09/12/2024 12.46, Corinna Vinschen via Cygwin wrote:
>>> On Dec 6 13:23, Federico Kircheis via Cygwin wrote:
>>>> Hello,
>>>>
>>>> was it considered to add a flag to cygpath to output a path in unc format?
>>>
>>> No. But it wouldn't be much work.
>>
>> It would be very nice if it ever happens.
>>
>>>> For example, the folder
>>>>
>>>> C:\test.
>>>>
>>>> cannot be accessed from many Windows applications (powershell and cmd
>>>> included) because of the trailing dot, while cygwin has no issue creating,
>>>> accessing and deleting such files/folders.
>>>>
>>>> Using an unc path
>>>>
>>>> \\?\C:\test.
>>>>
>>>> solves the issue for some programs, but cygpath currently misses an option
>>>> for creating such path.
>>>
>>> As a workaround you can just prepend the long path prefix:
>>>
>>> echo -n '\\?\'; cygpath ...
>>
>> Which is what I'm doing, plus special-casing
>>
>> 1)
>> root path, like C:\ , because for whatever reason \\?\C:\ is not valid, it
>> has to be a subfolder (and trying to trick it with \\?\C:\\ does not work
>> either).
>
> In which scenario? \\?\C:\ is just the same as \??\C:\ in NT speak, and
> that's a perfectly valid directory path.
I've never seen \??\C:\.
My test case, from powershell (which I do definitively _not_ know well
enough, otherwise I wouldn't be using cygwin) was
cd C:\ # success
cd \\?\C:\ # fail
cd C:\windows # success
cd \\?\C:\windows # success
and repeat the same operation with dir instead of ls.
The error message is that the "value of argument path is not valid"
I did some further testing: no amount of quoting (with ", ' and `)
helps, also replacing \ with / does not change any outcome.
For cd, the parameter -literal makes a difference
cd -literal \\?\C:\ # success
for dir, I did not find anything yet.
So I guess you are correct, although support from basic tools (cd and
dir at least) seems very suboptimal...
>> 2)
>> unmounted network drives (\\server\path)
>
> Yeah, those have a different prefix:
>
> \\?\UNC\server\share
>
>> I'm not sure how a --unc should handle those cases.
>> For all things I have in mind, not appending \\?\ is preferred, but someone
>> might expect a hard error.
>>
>> Either way, it is another reason why it makes sense for cygpath to handle
>> those cases, currently I have to parse it's output before prepending '\\?\'.
>
> I'll take a look.
>
>>>> Notice that creating a dos path leads to an error.
>>>
>>> I don't understand. Creating which DOS path with which application?
>>
>> I meant that it is not possible to create a DOS path to C:\test., thus using
>> a dos path is not a viable workaround to unc:
>>
>> ----
>>> cd 'C:/test.'
>>> cygpath -ws .
>> cygpath: cannot create short name of .
>> ----
>
> Don't use -s, it's just for the old short name style of DOS paths.
> Nobody should actually need this nowadays, and sometimes short paths
> don't even exist. It's a functionality inside the FS driver, afaik, and
> it can be switched off in the system.
>
> In your example, standard filenames work:
>
> $ cd /cygdrive/c
> $ mkdir test.
> $ cd test.
> $ cygpath -ws .
> cygpath: cannot create short name of C:\test.
> $ cygpath -wa .
> C:\test.
Yes, -wa works; I wanted to point out that DOS paths are not a viable
workaround.
I could have left it out from my first mail, we agree no need to iterate
further ;)
More information about the Cygwin
mailing list