Sign in Join

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

Mailing lists / lazarus / 2003-12

Wrong note in windows: Lazarus source directory notset

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Vincent Snijders
to Vincent Snijders: Lazarus gives a wrong note: Lazarus source directory not set, even if it is set…
Show quoted text 42 lines
On Sat, 20 Dec 2003 12:27:00 +0100 Vincent Snijders wrote: > On Sat, 20 Dec 2003 12:00:20 +0100 > Mattias Gaertner wrote: > > > On Fri, 19 Dec 2003 22:51:45 +0100 Vincent Snijders > > wrote: > > > > > Hi, > > > > > > Lazarus gives a wrong note: Lazarus source directory not set, > > > even if it is set correctly. The reason is a difference in > > > behaviour of the FileExists function. > > > > > > Lazarus appends the directory seperator ('/' or '\' depending on > > > the platform) to path given by the user. Under linux FileExists > > > returns true for /my/lazarus/source/dir and > > > /my/lazarus/source/dir/. Under windows c:\my\lazarus\source\dir > > > returns true, but c:\my\lazarus\source\dir\ returns false. > > > > > > IMO the most simple solution to solve this wrong not, would be > > > storing the dir without the appended directory seperator, but I > > > am not sure about the impact this would have for the rest of > > > lazarus. > > > > Probably none. The IDE trims and adds path delimiters as it needs. > > So, deleting the path delimiter will neither break, nor fix it > > completely. > > > > > > > There might be simplier solutions. > > > > I think, the only solution is to check all fileexists if they > > should be replaced by DirectoryExists. But there are a lot of > > places... > > I 'll start replacing FileExists with DirectoryExists, since > DirectoryExists doesn't get upset from a append directory separator. Why that? I added a ChompPathDelim to make sure.

At first I thought replacing FileExists with DirectoryExists would make things work.
To test things a bit further a made a testprogram: program direxists;

{$mode objfpc}{$H+}
uses
  Classes, SysUtils;
var
  path: string;
begin
  path := ExtractFileDir(ParamStr(0));
  writeln(format('FPC version: %s',[{$I %FPCVERSION}]));
  writeln(format('DirectoryExists(''%s''): ',[path]),
    DirectoryExists(path));
  writeln(format('FileExists(''%s''): ',[path]),
    FileExists(path));
  path := path + DirectorySeparator;
  writeln(format('DirectoryExists(''%s''): ',[path]),
    DirectoryExists(path));
  writeln(format('FileExists(''%s''): ',[path]),
    FileExists(path));
end.

On linux the output for fpc 1.0.11 and fpc 1.9.1 is the same, it doesn't matter if the name has a directory seperator appended: DirectoryExists('/home/vsds/lazarus/projects/bugs/fileexists'): TRUE FileExists('/home/vsds/lazarus/projects/bugs/fileexists'): TRUE DirectoryExists('/home/vsds/lazarus/projects/bugs/fileexists/'): TRUE FileExists('/home/vsds/lazarus/projects/bugs/fileexists/'): TRUE

On win32 the output depends on the fpc version:
FPC version: 1.0.11
DirectoryExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS'): TRUE FileExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS'): TRUE DirectoryExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS\'): TRUE FileExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS\'): FALSE

FPC version: 1.9.1
DirectoryExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS'): TRUE FileExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS'): TRUE DirectoryExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS\'): FALSE FileExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS\'): FALSE

Since I first tested with fpc 1.0.11, I thought replacing FileExists with DirectoryExists would solve the incomptible behaviour between linux and win32. But with fpc 1.9.1 that doesn't help.
There are two incompatibilities here:
1. FileExists doesn't behave the same on win32 and linux. (Is this a bug?)
2. DirectoryExists doesn't behave the same on win32 for fpc 1.0.11 and fpc 1.9. (Is this a bug?)

So unless these incompatibilties are fixed (by the fpc team), we should call DirectoryExists without appended directory seperator.

I see two ways to proceed then:
1. Making calls like
DirectoryExists(ChompPathDelim(EnvironmentOptions.LazarusDirectory))
2. In for example TEnvironmentOptions instead of

  FLazarusDirectory:=AppendPathDelim(TrimFilename(AValue));

do

  FLazarusDirectory:=ChompPathDelim(TrimFilename(AValue));

What do you prefer?

Regards,
Vincent.

Reply by email

Vincent Snijders

Hi,

Lazarus gives a wrong note: Lazarus source directory not set, even if it is set correctly. The reason is a difference in behaviour of the FileExists function.

Lazarus appends the directory seperator ('/' or '\' depending on the platform) to path given by the user. Under linux FileExists returns true for /my/lazarus/source/dir and /my/lazarus/source/dir/. Under windows c:\my\lazarus\source\dir returns true, but c:\my\lazarus\source\dir\ returns false.

IMO the most simple solution to solve this wrong not, would be storing the dir without the appended directory seperator, but I am not sure about the impact this would have for the rest of lazarus. There might be simplier solutions.

I hope I have given enough information to help you solve this bug.

Regards,
Vincent.

Reply by email

Mattias Gaertner
to Vincent Snijders
Show quoted text 33 lines
On Sat, 20 Dec 2003 12:00:20 +0100 Mattias Gaertner wrote: > On Fri, 19 Dec 2003 22:51:45 +0100 Vincent Snijders > wrote: > > > Hi, > > > > Lazarus gives a wrong note: Lazarus source directory not set, even > > if it is set correctly. The reason is a difference in behaviour of > > the FileExists function. > > > > Lazarus appends the directory seperator ('/' or '\' depending on the > > platform) to path given by the user. Under linux FileExists returns > > true for /my/lazarus/source/dir and /my/lazarus/source/dir/. Under > > windows c:\my\lazarus\source\dir returns true, but > > c:\my\lazarus\source\dir\ returns false. > > > > IMO the most simple solution to solve this wrong not, would be > > storing the dir without the appended directory seperator, but I am > > not sure about the impact this would have for the rest of lazarus. > > Probably none. The IDE trims and adds path delimiters as it needs. So, > deleting the path delimiter will neither break, nor fix it completely. > > > > There might be simplier solutions. > > I think, the only solution is to check all fileexists if they should > be replaced by DirectoryExists. But there are a lot of places... I 'll start replacing FileExists with DirectoryExists, since DirectoryExists doesn't get upset from a append directory separator.

Why that?
I added a ChompPathDelim to make sure.

BTW, I already replaced a few FileExists.

Mattias

Reply by email

Mattias Gaertner
to Vincent Snijders: Lazarus gives a wrong note: Lazarus source directory not set, even if it is set…
Show quoted text 15 lines
Hi, Lazarus gives a wrong note: Lazarus source directory not set, even if it is set correctly. The reason is a difference in behaviour of the FileExists function. Lazarus appends the directory seperator ('/' or '\' depending on the platform) to path given by the user. Under linux FileExists returns true for /my/lazarus/source/dir and /my/lazarus/source/dir/. Under windows c:\my\lazarus\source\dir returns true, but c:\my\lazarus\source\dir\ returns false. IMO the most simple solution to solve this wrong not, would be storing the dir without the appended directory seperator, but I am not sure about the impact this would have for the rest of lazarus.

Probably none. The IDE trims and adds path delimiters as it needs. So, deleting the path delimiter will neither break, nor fix it completely.

There might be simplier solutions.

I think, the only solution is to check all fileexists if they should be replaced by DirectoryExists. But there are a lot of places...

Mattias

Reply by email

Vincent Snijders
to Vincent Snijders: Lazarus gives a wrong note: Lazarus source directory not set, even if it is set…
Show quoted text 27 lines
On Fri, 19 Dec 2003 22:51:45 +0100 Vincent Snijders wrote: > Hi, > > Lazarus gives a wrong note: Lazarus source directory not set, even > if it is set correctly. The reason is a difference in behaviour of > the FileExists function. > > Lazarus appends the directory seperator ('/' or '\' depending on the > platform) to path given by the user. Under linux FileExists returns > true for /my/lazarus/source/dir and /my/lazarus/source/dir/. Under > windows c:\my\lazarus\source\dir returns true, but > c:\my\lazarus\source\dir\ returns false. > > IMO the most simple solution to solve this wrong not, would be > storing the dir without the appended directory seperator, but I am > not sure about the impact this would have for the rest of lazarus. Probably none. The IDE trims and adds path delimiters as it needs. So, deleting the path delimiter will neither break, nor fix it completely. > There might be simplier solutions. I think, the only solution is to check all fileexists if they should be replaced by DirectoryExists. But there are a lot of places...

I 'll start replacing FileExists with DirectoryExists, since DirectoryExists doesn't get upset from a append directory separator.

Vincent.

Reply by email

Mattias Gaertner
to Vincent Snijders: Lazarus gives a wrong note: Lazarus source directory not set, even if it is set…
Show quoted text 7 lines
To test things a bit further a made a testprogram: program direxists; {$mode objfpc}{$H+} uses Classes, SysUtils;

Here you must add FileCtrl. The IDE uses it. Some functions in FileCtrl were added later to sysutils with the same name, but not necessarily the exact behaviour. There are now ambigious functions.
I will rename the DirectoryExists function in FileCtrl to DirPathExists.

Show quoted text 23 lines
var path: string; begin path := ExtractFileDir(ParamStr(0)); writeln(format('FPC version: %s',[{$I %FPCVERSION}])); writeln(format('DirectoryExists(''%s''): ',[path]), DirectoryExists(path)); writeln(format('FileExists(''%s''): ',[path]), FileExists(path)); path := path + DirectorySeparator; writeln(format('DirectoryExists(''%s''): ',[path]), DirectoryExists(path)); writeln(format('FileExists(''%s''): ',[path]), FileExists(path)); end. On linux the output for fpc 1.0.11 and fpc 1.9.1 is the same, it doesn't matter if the name has a directory seperator appended: DirectoryExists('/home/vsds/lazarus/projects/bugs/fileexists'): TRUE FileExists('/home/vsds/lazarus/projects/bugs/fileexists'): TRUE DirectoryExists('/home/vsds/lazarus/projects/bugs/fileexists/'): TRUE FileExists('/home/vsds/lazarus/projects/bugs/fileexists/'): TRUE

same under wine (with and without FileCtrl).

Show quoted text 21 lines
On win32 the output depends on the fpc version: FPC version: 1.0.11 DirectoryExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS'): TRUE FileExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS'): TRUE DirectoryExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS\'): TRUE FileExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS\'): FALSE FPC version: 1.9.1 DirectoryExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS'): TRUE FileExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS'): TRUE DirectoryExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS\'): FALSE FileExists('V:\LAZARUS\PROJECTS\BUGS\FILEEXISTS\'): FALSE Since I first tested with fpc 1.0.11, I thought replacing FileExists with DirectoryExists would solve the incomptible behaviour between linux and win32. But with fpc 1.9.1 that doesn't help. There are two incompatibilities here: 1. FileExists doesn't behave the same on win32 and linux. (Is this a bug?) 2. DirectoryExists doesn't behave the same on win32 for fpc 1.0.11 and fpc 1.9. (Is this a bug?)

Maybe. The question is, which one is right. You can argue, that for Delphi compatibility the linux behaviour is wrong. But to reduce code in the IDE we need a function, that test directory paths with appended path delimiter.

Show quoted text 10 lines
So unless these incompatibilties are fixed (by the fpc team), we should call DirectoryExists without appended directory seperator. I see two ways to proceed then: 1. Making calls like DirectoryExists(ChompPathDelim(EnvironmentOptions.LazarusDirectory)) 2. In for example TEnvironmentOptions instead of FLazarusDirectory:=AppendPathDelim(TrimFilename(AValue)); do FLazarusDirectory:=ChompPathDelim(TrimFilename(AValue));

IMO appending a path delimiter makes it easy to spot (especially for newbies), that the IDE expects a file to be a directory.

What do you prefer?

1. add a new platform independent function that does DirectoryExists(ChompPathDelim()).

Mattias

Reply by email