FileExists inconsistency

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

FileExists inconsistency

Henry Vermaak
Hi all

FileExists seems to be inconsistent between linux and windows.
FileExists in linux returns true for a directory, but not in windows.
The windows behaviour is consistent with Delphi, though, and I assume
that's correct.

Can anyone confirm or comment on this?

Henry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Vincent Snijders
Henry Vermaak schreef:
> Hi all
>
> FileExists seems to be inconsistent between linux and windows.
> FileExists in linux returns true for a directory, but not in windows.
> The windows behaviour is consistent with Delphi, though, and I assume
> that's correct.
>
> Can anyone confirm or comment on this?
>

I can confirm this.

Vincent
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Bugzilla from daniel.mantione@freepascal.org


Op Wed, 3 Jan 2007, schreef Vincent Snijders:

> Henry Vermaak schreef:
> > Hi all
> >
> > FileExists seems to be inconsistent between linux and windows.
> > FileExists in linux returns true for a directory, but not in windows.
> > The windows behaviour is consistent with Delphi, though, and I assume
> > that's correct.
> >
> > Can anyone confirm or comment on this?
> >
>
> I can confirm this.
There is no getting away that Dos filesystem handling is different
from Unix file handling. On Dos like platforms, a filename with
a same name as a subdirectory can exist in the same directory. In other
words, it should return false.

On the other hand, in Unix, it should return true because otherwise code
like:

if not fileexists('abcd') then
  begin
    assign(f,'abcd');
    rewrite(f);
  end;

... becomes unreliable.

Daniël
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Henry Vermaak
> There is no getting away that Dos filesystem handling is different
> from Unix file handling. On Dos like platforms, a filename with
> a same name as a subdirectory can exist in the same directory. In other
> words, it should return false.
>

I cannot create a file with the same name as a subdir under Windows XP
on ntfs or fat32...

> On the other hand, in Unix, it should return true because otherwise code
> like:
>
> if not fileexists('abcd') then
>   begin
>     assign(f,'abcd');
>     rewrite(f);
>   end;
>
> ... becomes unreliable.
>

...so that means that this code will also be unreliable on windows.
In short: the 2 file systems are consistent with their behaviour in
this respect, but the FileExists is not.

Maybe there's something I'm missing?

Henry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Bugzilla from daniel.mantione@freepascal.org


Op Wed, 3 Jan 2007, schreef Henry Vermaak:

> > There is no getting away that Dos filesystem handling is different
> > from Unix file handling. On Dos like platforms, a filename with
> > a same name as a subdirectory can exist in the same directory. In other
> > words, it should return false.
> >
>
> I cannot create a file with the same name as a subdir under Windows XP
> on ntfs or fat32...
>
> > On the other hand, in Unix, it should return true because otherwise code
> > like:
> >
> > if not fileexists('abcd') then
> > begin
> > assign(f,'abcd');
> > rewrite(f);
> > end;
> >
> > ... becomes unreliable.
> >
>
> ...so that means that this code will also be unreliable on windows.
> In short: the 2 file systems are consistent with their behaviour in
> this respect, but the FileExists is not.
>
> Maybe there's something I'm missing?
No, because in a Dos like filesystem, a direcory abcd will still allow a
file abcd to be created. In other words, fileexists returns false so the
file can be created.

In a Unix like filesystem, a directory abcd will prevent a file abcd to be
created, so fileexists returns true.

In short, in Dos filesystems, directories are not considered files. In
Unix filesystems they are considered files.

Daniël
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Marco van de Voort
In reply to this post by Henry Vermaak
> Maybe there's something I'm missing?

DirectoryExists?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Jonas Maebe-2
In reply to this post by Bugzilla from daniel.mantione@freepascal.org

On 3 jan 2007, at 16:46, Daniël Mantione wrote:

> Op Wed, 3 Jan 2007, schreef Henry Vermaak:
>
>>> There is no getting away that Dos filesystem handling is different
>>> from Unix file handling. On Dos like platforms, a filename with
>>> a same name as a subdirectory can exist in the same directory. In  
>>> other
>>> words, it should return false.
>>>
>>
>> I cannot create a file with the same name as a subdir under  
>> Windows XP
>> on ntfs or fat32...
[snip]

>> Maybe there's something I'm missing?
>
> No, because in a Dos like filesystem, a direcory abcd will still  
> allow a
> file abcd to be created. In other words, fileexists returns false  
> so the
> file can be created.

As he mentioned above, that does not work for him. It also does not  
work for me in MS Dos 6.22 and fat16 (running in an emulator, but I  
doubt that changes anything for this sort of stuff):




Jonas



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

pastedGraphic.png (18K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Henry Vermaak
In reply to this post by Bugzilla from daniel.mantione@freepascal.org
> > > On the other hand, in Unix, it should return true because otherwise code
> > > like:
> > >
> > > if not fileexists('abcd') then
> > > begin
> > > assign(f,'abcd');
> > > rewrite(f);
> > > end;
> > >

I just wrote a program using this code.  It works in linux, but
crashes in windows.  See attached...

Henry

fexists.JPG (59K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Henry Vermaak
In reply to this post by Marco van de Voort
>
> DirectoryExists?

Yes, I know about that.  Looks like you have to use FileExists and
DirectoryExists together.

Henry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Bugzilla from daniel.mantione@freepascal.org
In reply to this post by Jonas Maebe-2


Op Wed, 3 Jan 2007, schreef Jonas Maebe:

> > > Maybe there's something I'm missing?
> >
> > No, because in a Dos like filesystem, a direcory abcd will still allow a
> > file abcd to be created. In other words, fileexists returns false so the
> > file can be created.
>
> As he mentioned above, that does not work for him. It also does not work for
> me in MS Dos 6.22 and fat16 (running in an emulator, but I doubt that changes
> anything for this sort of stuff):

Whoops, I overlooked that part of his answer. You're right, I cannot
either (PC-Dos 2000, no emulation). This is weird, because I have been
able to do this in the past. But it has then been changed a long time ago
already.

Daniël
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Jason P Sage
In reply to this post by Henry Vermaak
I've written stuff in freepascal that can load and parse a directory and
decipher if it’s a directory or a file - even on POSIX (linux - Fedora 5).

I'm not saying this is a big achievement - but perhaps - at an expense of
speed - but in definitive returned results - I wonder if it would be prudent
to add a filexists routine or make the current one - do this type of
"thorugh checks".

I am aware of running to issue though with permissions - but these usually
make sense. If the file doesn't exist - but does - you don't have write
permissions.

I made a routine that goes through a couple steps - (probably the wrong way
but is portable) to both READ ONLY and READ WRITE (no actual writing) the
file just to see if I have read access and alternatively read/write.

This is great because if I need to verify a configuration file exists - I do
not necessarily need write permission ... and sometimes you do. Having a
little more info allows one to make more detailed error log files - and user
interface "messages" so users and administrators - heck - us
heads-down-coders can figure out what and why quickly when something doesn't
go as planned.
 
Best Regards,

Jason P Sage
[hidden email]


http://www.jegas.com


 

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.3/614 - Release Date: 1/2/2007
2:58 PM
 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Marco van de Voort
In reply to this post by Bugzilla from daniel.mantione@freepascal.org
>
> Whoops, I overlooked that part of his answer. You're right, I cannot
> either (PC-Dos 2000, no emulation). This is weird, because I have been
> able to do this in the past. But it has then been changed a long time ago
> already

Afaik some of the FS Dos habits changed going from FCBS to handle based
programming. This could be one of them.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Tomas Hajny
Marco van de Voort wrote:
>>
>> Whoops, I overlooked that part of his answer. You're right, I cannot
>> either (PC-Dos 2000, no emulation). This is weird, because I have been
>> able to do this in the past. But it has then been changed a long time
>> ago
>> already
>
> Afaik some of the FS Dos habits changed going from FCBS to handle based
> programming. This could be one of them.

FCBS? I don't know when Daniel started coding, but handles have been
supported since MS-DOS 3.3 at latest, so I wouldn't assume Daniel to
remember those times that well? FWIW, I've never seen a DOS machine with
equally named files and directories (nor such a machine with another
DOS-like OS).

In any case, I'd consider the reported behaviour (for Linux) buggy - is
somebody going to fix it? Maybe the original reporter might add it to our
bug repository?

Tomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Marco van de Voort

> In any case, I'd consider the reported behaviour (for Linux) buggy - is
> somebody going to fix it? Maybe the original reporter might add it to our
> bug repository?

Problem is that it is "FileExists". On Windows a directory is not a file,
under *nix it is. One some you even can edit a directory with a texteditor
if you are brave. (most modern texteditors are protected against this, but
often e.g. single user mode static tools aren't)

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Bugzilla from daniel.mantione@freepascal.org
In reply to this post by Tomas Hajny


Op Thu, 4 Jan 2007, schreef Tomas Hajny:

> Marco van de Voort wrote:
> >>
> >> Whoops, I overlooked that part of his answer. You're right, I cannot
> >> either (PC-Dos 2000, no emulation). This is weird, because I have been
> >> able to do this in the past. But it has then been changed a long time
> >> ago
> >> already
> >
> > Afaik some of the FS Dos habits changed going from FCBS to handle based
> > programming. This could be one of them.
>
> FCBS? I don't know when Daniel started coding, but handles have been
> supported since MS-DOS 3.3 at latest, so I wouldn't assume Daniel to
> remember those times that well? FWIW, I've never seen a DOS machine with
> equally named files and directories (nor such a machine with another
> DOS-like OS).
Well, I have a good memory, but... :)

Handles were introduced in Dos 2.0. The Dos version on my first PC was
4.0 (before I used a Commodore 64), so it cannot have been FCBS.

Daniël
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Tomas Hajny
In reply to this post by Marco van de Voort
Marco van de Voort wrote:

>
>> In any case, I'd consider the reported behaviour (for Linux) buggy - is
>> somebody going to fix it? Maybe the original reporter might add it to
>> our
>> bug repository?
>
> Problem is that it is "FileExists". On Windows a directory is not a file,
> under *nix it is. One some you even can edit a directory with a texteditor
> if you are brave. (most modern texteditors are protected against this, but
> often e.g. single user mode static tools aren't)

The point is how the function is defined (and documented), not how it is
named, IMHO. The fact that everything can be accessed as a "file" on *nix
doesn't mean that semantics of a RTL function name has to be derived from
a platform specific definition of the term "file".

Tomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FileExists inconsistency

Marco van de Voort
> Marco van de Voort wrote:
> >
> >> In any case, I'd consider the reported behaviour (for Linux) buggy - is
> >> somebody going to fix it? Maybe the original reporter might add it to
> >> our
> >> bug repository?
> >
> > Problem is that it is "FileExists". On Windows a directory is not a file,
> > under *nix it is. One some you even can edit a directory with a texteditor
> > if you are brave. (most modern texteditors are protected against this, but
> > often e.g. single user mode static tools aren't)
>
> The point is how the function is defined (and documented), not how it is
> named,

That's exactly what I meant. It is defined in terms of "file", a concept
that differs.

Note that I don't mind if it is fixed. Personally I'd look what Kylix does,
and follow that, otherwise we still have a difference somewhere.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Build FP Ide with GDB support

Jan Jelowicki
In reply to this post by Jonas Maebe-2
Hi to all,

The freepascal IDE included in standard 2.0.4 RPM has no debugger
support. There are also *.tgz binaries in FreePascal repositories,
and they contain GDB-enabled fp executable. Unfortunately, one of
the machines I would like do use for debugging is too old for that
binaries -- it is RedHat 9 with glibc 2.3.2, while precompiled fp
requires at least 2.3.4.

Trying to make FreePascal IDE from 2.0.4 sources I got a message
from the linker:
"LibGDB was not found, IDE has no Debugger support".
I have no libgdb.a in my system, and I am afraid that no conforming
package provides it.

glibc-2.3.2-27.9.7.2.legacy
gdb-5.3post-0.20021129.18

Yes, I know they are very old but now I cannot upgrade this machine,
it has to work stable with all its software.

How should I obtain or generate libgdb.a in order to make fp IDE with gdb support?


With regards,

                                                   Jan Je/lowicki
-----------------------------------------------------------------
Department of Mathematics                      Katedra Matematyki
University of Life Sciences              Uniwersytet Przyrodniczy
                          Wroc/law, POLAND
-----------------------------------------------------------------
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

RE: Build FP Ide with GDB support

Lee, John
You can find all fpc versions versions of the libgdb*.zips (they contain all the .a files needed) on the freepascal ftp site /contribs/libgdb/... The ones used for v2.0.4 were mostly v6.2.1 & probably for linux eg for windows IIRC. You have to unzip the appropriate libgdb into the appropriate directory eg

\libgdb\win32\i386 for windows so that it is found. You will then get 'gdb found vxxx' or a similar message in the make log.

This certainly works for win32 on v2.0.4, v2.0.5, and v2.1 ...not sure about your linux target & version...

HTH Regards John  

>
>
> Hi to all,
>
> The freepascal IDE included in standard 2.0.4 RPM has no debugger
> support. There are also *.tgz binaries in FreePascal repositories,
> and they contain GDB-enabled fp executable. Unfortunately, one of
> the machines I would like do use for debugging is too old for that
> binaries -- it is RedHat 9 with glibc 2.3.2, while precompiled fp
> requires at least 2.3.4.
>
> Trying to make FreePascal IDE from 2.0.4 sources I got a message
> from the linker:
> "LibGDB was not found, IDE has no Debugger support".
> I have no libgdb.a in my system, and I am afraid that no conforming
> package provides it.
>
> glibc-2.3.2-27.9.7.2.legacy
> gdb-5.3post-0.20021129.18
>
> Yes, I know they are very old but now I cannot upgrade this machine,
> it has to work stable with all its software.
>
> How should I obtain or generate libgdb.a in order to make fp
> IDE with gdb support?
>
>
> With regards,
>
>                                                    Jan Je/lowicki
> -----------------------------------------------------------------
> Department of Mathematics                      Katedra Matematyki
> University of Life Sciences              Uniwersytet Przyrodniczy
>                           Wroc/law, POLAND
> -----------------------------------------------------------------
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>


This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Build FP Ide with GDB support

Bugzilla from daniel.mantione@freepascal.org
In reply to this post by Jan Jelowicki


Op Thu, 4 Jan 2007, schreef Jan Jelowicki:

> Hi to all,
>
> The freepascal IDE included in standard 2.0.4 RPM has no debugger
> support.

That is bad... But it will enable you to run the IDE indeed, because
without GDB, the IDE does not use libc.

> There are also *.tgz binaries in FreePascal repositories,
> and they contain GDB-enabled fp executable. Unfortunately, one of
> the machines I would like do use for debugging is too old for that
> binaries -- it is RedHat 9 with glibc 2.3.2, while precompiled fp
> requires at least 2.3.4.
>
> Trying to make FreePascal IDE from 2.0.4 sources I got a message
> from the linker:
> "LibGDB was not found, IDE has no Debugger support".
> I have no libgdb.a in my system, and I am afraid that no conforming
> package provides it.
>
> glibc-2.3.2-27.9.7.2.legacy
> gdb-5.3post-0.20021129.18
>
> Yes, I know they are very old but now I cannot upgrade this machine,
> it has to work stable with all its software.
>
> How should I obtain or generate libgdb.a in order to make fp IDE with gdb support?
It is available on ftp.freepascal.org, but, since the dependency on glibc
is caused by libgdb, this won't help you.

You need to compile gdb yourself, after compilation there will be a
libgdb.a in the gdb source directory. You will also need libiberty.a and
libbfd.a there, which should *not* be on your system already, if they are,
rename them so the compiler cannot find the ones already on your system.

Daniël
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
12