Am Donnerstag, den 29.06.2006, 16:16 +0200 schrieb Marc Santhoff:

> How can i detect if sysutils.FindFirst() or FindNext() fails lacking
> permissions?

As a quick and dirty hack I added an addtitional "stat" on the starting
dir for FindFirst and let it bail out early for protecting
"ErrNo" ("opendir" gives no reasonable error code on FreeBSD). This in
combination with a bug fix in my code using FindFirst solves the problem
for me for now. Most important is I'm no longer blocked working on my
code.

I'm aware of the fact that there might be problems when hitting an
unreadable item while recursing, but for my program I can rule out this
case.

This was done on FreeBSD 4.11 with fpc 2.0.2 release.

<diff>
*** sysutils.pp.org     Thu Jun 29 00:06:06 2006
--- sysutils.pp Fri Jun 30 05:07:22 2006
***************
*** 479,490 ****
--- 479,496 ----
    buffer  : pdirent;
    root,
    current : pglob;
+   SInfo : Stat;
+   res: longint;
+   temp3: string[255];
  begin
  { Get directory }
    temp:=dirname(path);
    if temp='' then
     temp:='.';
+   temp3 := temp+'/.'+#0;
    temp:=temp+#0;
+   res := fpstat(temp3, SInfo);
+   if (res<>0) then exit(nil);
    thedir:=fpopendir(@temp[1]);
    if thedir=nil then
      exit(nil);
</diff>

Maybe lateron I'll come back on this topic. Did I understand correctly
that a new implementation :-

- does not need to defer "readdir" or "stat" calls for being fast enough
on modern system implementations

- there could be a check for looping symlinks

- anything else?

Regards,
Marc


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to