[Lazarus] FileExistsUTF8 and long paths

Bart bartjunk64 at gmail.com
Sun Jan 17 12:42:25 CET 2016


On 1/16/16, Jürgen Hestermann <juergen.hestermann at gmx.de> wrote:

> Well, at least when the path is too long (length(FileName>MAXPATH))
> it can prepend \\?\ because it will fail without it anyway.

That won't do for the same reasons as explained above.
Say you have a directory: c:\maxpathchars\1\2\3\
Now cehcking for ..\..\foobar will still fail if
c:\maxpathchars\1\foorbar exists, unless you have a folder in
c:\maxpathchars\1\2\3\ that actually has the name  '..' etc.
I.o.w expanding the filename cannot be done anymore.

Note that even Windows itself (at least windows explorer) cannot handle this.
I once unzipped a file with such a filename (produced on linux of course).
It unzipped well and FileexistsUtf8('\\?\realfilename) worked well.
(Testing this was the reason I did this.)

After that windows was unable to remove the file in question.
I tried various tools for that, icluding rm - R *.
No such luck.

In the end I used a bootable linux dvd (puppy linux), mounted the
partition in question and used the filemanger from that distro to
remove the folder and file.

To me it looks like a rather odd design desicion by MS have a MAXPATH
but then have obscure ways to circumvent that.

AFACS it cannot be resolved/fixed in a manner that will not break
backwards compatibility.
Further more: this is not something that belongs to Lazarus, but to fpc.

> I did not find any comments that mentions long paths

You need new glasses then ;-)

=== code ==
  //if Filename uses ExtendedLengthPath scheme then it cannot be expanded
  //AND it should not be altered by ForcePathDelims or ResolveDots
  //See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
  if (Length(Fn) > 3) and (Fn[1] = PathDelim) and (Fn[2] = PathDelim) and
     (Fn[3] = '?') and (Fn[4] = PathDelim) //Do NOT use
AllowDirectorySeparators here!
     then Exit;
=== end code ===

Bart




More information about the Lazarus mailing list