Sign in Join

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

Mailing lists / fpc-pascal / 2007-01

FileExists inconsistency

22 messages · 9 people · –

Reply by email Subscribe to this list Your subscription

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

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

Vincent Snijders
to Henry Vermaak
Henry Vermaak wrote 9 lines
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

Daniël Mantione
to Vincent Snijders

Op Wed, 3 Jan 2007, schreef Vincent Snijders:

Show quoted text 12 lines
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

Henry Vermaak
to Daniël Mantione
Show quoted text 5 lines
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...

Show quoted text 11 lines
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

Daniël Mantione
to Henry Vermaak

Op Wed, 3 Jan 2007, schreef Henry Vermaak:

Show quoted text 26 lines
> 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

Jonas Maebe
to Daniël Mantione: Op Wed, 3 Jan 2007, schreef Henry Vermaak: No, because in a Dos like filesystem, a…
Daniël Mantione wrote 12 lines
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]

Show quoted text 7 lines
> 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

Daniël Mantione
to Jonas Maebe: [snip] As he mentioned above, that does not work for him. It also does not work for me in…

Op Wed, 3 Jan 2007, schreef Jonas Maebe:

Show quoted text 9 lines
> > 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

Jason P Sage

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

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
Marco van de Voort
to Daniël Mantione: Op Wed, 3 Jan 2007, schreef Jonas Maebe: Whoops, I overlooked that part of his answer.…
Show quoted text 5 lines
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.

Tomas Hajny
to Marco van de Voort
Marco van de Voort wrote 9 lines
> > 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

Marco van de Voort
to Tomas Hajny
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)

Daniël Mantione
to Tomas Hajny: FCBS? I don't know when Daniel started coding, but handles have been supported since…

Op Thu, 4 Jan 2007, schreef Tomas Hajny:

Show quoted text 16 lines
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

Tomas Hajny
to Marco van de Voort: Problem is that it is "FileExists". On Windows a directory is not a file, under *nix it…
Marco van de Voort wrote 10 lines
> 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

Marco van de Voort
to Tomas Hajny
Show quoted text 14 lines
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.

Jan Jelowicki
to Jonas Maebe: [snip] As he mentioned above, that does not work for him. It also does not work for me in…

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
-----------------------------------------------------------------

Lee, John
to Jan Jelowicki

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

Show quoted text 39 lines
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 - 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.

Daniël Mantione
to Jan Jelowicki: The freepascal IDE included in standard 2.0.4 RPM has no debugger support. There are also…

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.

Show quoted text 19 lines
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

Daniël Mantione
to Daniël Mantione

Op Thu, 4 Jan 2007, schreef Daniël Mantione:

Op Thu, 4 Jan 2007, schreef Jan Jelowicki: > glibc-2.3.2-27.9.7.2.legacy > gdb-5.3post-0.20021129.18

I forgot: GDB 5.3 won't do it. You need to compile a 6.x gdb.

Daniël

Jan Jelowicki
to Jonas Maebe: [snip] As he mentioned above, that does not work for him. It also does not work for me in…

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.

I have found this in the archive:
http://lists.freepascal.org/lists/fpc-pascal/2006-August/011726.html but no version of libgdb binaries available from ftp.freepascal.org allows for successfull linking.

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
-----------------------------------------------------------------