[Lazarus] FileExistsUTF8() difference between Unix/Windows

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] FileExistsUTF8() difference between Unix/Windows

Free Pascal - Lazarus mailing list
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.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] FileExistsUTF8() difference between Unix/Windows

Free Pascal - Lazarus mailing list
On Wed, Sep 18, 2019 at 9:01 PM Torsten Bonde Christiansen via lazarus
<[hidden email]> 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.


--
Bart
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] FileExistsUTF8() difference between Unix/Windows

Free Pascal - Lazarus mailing list
On 18/09/2019 23.23, Bart via lazarus wrote:
> On Wed, Sep 18, 2019 at 9:01 PM Torsten Bonde Christiansen via lazarus
> <[hidden email]> 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.


--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] FileExistsUTF8() difference between Unix/Windows

Free Pascal - Lazarus mailing list
On Wed, Sep 18, 2019 at 11:26 PM Torsten Bonde Christiansen via
lazarus <[hidden email]> 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.

--
Bart



--
Bart
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] FileExistsUTF8() difference between Unix/Windows

Free Pascal - Lazarus mailing list


On Wed, 18 Sep 2019, Bart via lazarus wrote:

> On Wed, Sep 18, 2019 at 11:26 PM Torsten Bonde Christiansen via
> lazarus <[hidden email]> 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.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] FileExistsUTF8() difference between Unix/Windows

Free Pascal - Lazarus mailing list
On Thu, 19 Sep 2019 00:02:19 +0200 (CEST)
Michael Van Canneyt via lazarus <[hidden email]> wrote:

> On Wed, 18 Sep 2019, Bart via lazarus wrote:
>
> > On Wed, Sep 18, 2019 at 11:26 PM Torsten Bonde Christiansen via
> > lazarus <[hidden email]> 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] FileExistsUTF8() difference between Unix/Windows

Free Pascal - Lazarus mailing list
On Fri, Sep 20, 2019 at 8:56 PM Mattias Gaertner via lazarus
<[hidden email]> wrote:

Old Windows version:

> > >> 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] FileExistsUTF8() difference between Unix/Windows

Free Pascal - Lazarus mailing list
On Sat, 21 Sep 2019 18:24:28 +0200
Bart via lazarus <[hidden email]> wrote:

>[...]
> > 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] FileExistsUTF8() difference between Unix/Windows

Free Pascal - Lazarus mailing list
On Sat, Sep 21, 2019 at 7:15 PM Mattias Gaertner via lazarus
<[hidden email]> 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus