Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2019-09

FileExistsUTF8() difference between Unix/Windows

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Torsten Bonde Christiansen

Is it a bug that FileExistsUTF8(...) reports true/false differently for folders in Unix and Windows.

On a unix platform (Mac/Linux tested) FileExistsUTF8() will return true to both folders and files

On windows platform FileExistsUTF8 will return true on files, but false on folders.

Best regards
Torsten.

Reply by email

Torsten Bonde Christiansen
to Bart
Bart wrote 8 lines
On Wed, Sep 18, 2019 at 9:01 PM Torsten Bonde Christiansen via lazarus wrote: > Is it a bug that FileExistsUTF8(...) reports true/false differently for > folders in Unix and Windows. Thet are just wrappers for fpc's FileExists() nowadays.

No entirely though. The Unix version is mostly a wrapper, yes - but the Windows version do some additional filtering:

function FileExistsUTF8(const Filename: string): boolean;
var
   Attr: Longint;
begin
   Attr := FileGetAttrUTF8(FileName);
   if Attr  -1 then
     Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0
   else
     Result:=False;
end;

Hence my question....

-Torsten.

Reply by email

Bart
to Torsten Bonde Christiansen
PM Torsten Bonde Christiansen wrote 13 lines
No entirely though. The Unix version is mostly a wrapper, yes - but the Windows version do some additional filtering: function FileExistsUTF8(const Filename: string): boolean; var Attr: Longint; begin Attr := FileGetAttrUTF8(FileName); if Attr -1 then Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0 else Result:=False; end;

Not anymore in trunk:

function FileExistsUTF8(const Filename: string): boolean;
begin
  Result := SysUtils.FileExists(Filename);
end;

This will return False for directories.
(The test for (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0 is done by fpc now).

On *nix everything is a file, so folders are reported to be files as well AFAIK.

Bart -- Bart

Reply by email

Michael Van Canneyt
to Bart
Bart wrote 28 lines
On Wed, Sep 18, 2019 at 11:26 PM Torsten Bonde Christiansen via lazarus wrote: > No entirely though. The Unix version is mostly a wrapper, yes - but the > Windows version do some additional filtering: > > function FileExistsUTF8(const Filename: string): boolean; > var > Attr: Longint; > begin > Attr := FileGetAttrUTF8(FileName); > if Attr -1 then > Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0 > else > Result:=False; > end; Not anymore in trunk: function FileExistsUTF8(const Filename: string): boolean; begin Result := SysUtils.FileExists(Filename); end; This will return False for directories. (The test for (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0 is done by fpc now). On *nix everything is a file, so folders are reported to be files as well AFAIK.

SysUtils.FileExists also returns false for directories, to match windows behavour.

Michael.

Reply by email

Mattias Gaertner
to Michael Van Canneyt
Show quoted text 35 lines
On Wed, 18 Sep 2019, Bart via lazarus wrote: > On Wed, Sep 18, 2019 at 11:26 PM Torsten Bonde Christiansen via > lazarus wrote: > >> No entirely though. The Unix version is mostly a wrapper, yes - >> but the Windows version do some additional filtering: >> >> function FileExistsUTF8(const Filename: string): boolean; >> var >> Attr: Longint; >> begin >> Attr := FileGetAttrUTF8(FileName); >> if Attr -1 then >> Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0 >> else >> Result:=False; >> end; > > Not anymore in trunk: > > function FileExistsUTF8(const Filename: string): boolean; > begin > Result := SysUtils.FileExists(Filename); > end; > > This will return False for directories. > (The test for (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0 is done by > fpc now). > > On *nix everything is a file, so folders are reported to be files > as well AFAIK. SysUtils.FileExists also returns false for directories, to match windows behavour.

I added an incompatibility note:
https://wiki.lazarus.freepascal.org/Lazarus_2.2.0_release_notes#LazUtils_Changes

Mattias

Reply by email

Bart
to Mattias Gaertner

On Fri, Sep 20, 2019 at 8:56 PM Mattias Gaertner via lazarus wrote:

Old Windows version:

Show quoted text 14 lines
> >> function FileExistsUTF8(const Filename: string): boolean; > >> var > >> Attr: Longint; > >> begin > >> Attr := FileGetAttrUTF8(FileName); > >> if Attr -1 then > >> Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0 > >> else > >> Result:=False; > >> end; > > I added an incompatibility note: https://wiki.lazarus.freepascal.org/Lazarus_2.2.0_release_notes#LazUtils_Changes

I think that is incorrect.
As you can see above the old version also returned FALSE for directories (it used the same logic as the Windows implementation of FileExists).

The reason the implementation has changed is that since LCL is UTF8 the automatic conversion fpc does is now lossless, which it wasn't before 3.0.

Bart

Reply by email

Mattias Gaertner
to Bart
Show quoted text 12 lines
[...] > I added an incompatibility note: > https://wiki.lazarus.freepascal.org/Lazarus_2.2.0_release_notes#LazUtils_Changes I think that is incorrect. As you can see above the old version also returned FALSE for directories (it used the same logic as the Windows implementation of FileExists). The reason the implementation has changed is that since LCL is UTF8 the automatic conversion fpc does is now lossless, which it wasn't before 3.0.

You are right. So the change is actually: FileExistsUT8 no longer supports fpc 2.6.4. Right?

Mattias

Reply by email

Bart
to Mattias Gaertner
PM Mattias Gaertner wrote
You are right. So the change is actually: FileExistsUT8 no longer supports fpc 2.6.4. Right?

I don't think Lazarus supports 2.6.4 anymore.
"Officially" we support current stable and the previous stable version of fpc, so that would be 3.0.4 and 3.0.2 ATM.
(Maybe even 3.0.0)

I _think_ that if you define DisableUtf8RTL then unicode isn't supported in these routines anymore.
I never tested that.
Having that define is like fighting the system, not using it.

IIRC it was debated in https://bugs.freepascal.org/view.php?id=35512

Bart

Reply by email