Selaa lähdekoodia

* do not mark all found files with Find* as "faHidden" if the search path
starts with './' (mantis #14020)
* also mark files whose name starts with '.' that are found in subdirectories
as faHidden (not reported, but was due to a similar error)
- removed some unused variables related to the Find* functionality

git-svn-id: trunk@13307 -

Jonas Maebe 16 vuotta sitten
vanhempi
commit
25463000ac
4 muutettua tiedostoa jossa 108 lisäystä ja 11 poistoa
  1. 2 0
      .gitattributes
  2. 7 11
      rtl/unix/sysutils.pp
  3. 36 0
      tests/webtbs/tw14020.pp
  4. 63 0
      tests/webtbs/tw14020a.pp

+ 2 - 0
.gitattributes

@@ -9166,6 +9166,8 @@ tests/webtbs/tw13984.pp svneol=native#text/plain
 tests/webtbs/tw13992a.pp svneol=native#text/plain
 tests/webtbs/tw1401.pp svneol=native#text/plain
 tests/webtbs/tw14019.pp svneol=native#text/plain
+tests/webtbs/tw14020.pp svneol=native#text/plain
+tests/webtbs/tw14020a.pp svneol=native#text/plain
 tests/webtbs/tw1407.pp svneol=native#text/plain
 tests/webtbs/tw1408.pp svneol=native#text/plain
 tests/webtbs/tw1409.pp svneol=native#text/plain

+ 7 - 11
rtl/unix/sysutils.pp

@@ -542,17 +542,18 @@ begin
 end;
 
 
-Function LinuxToWinAttr (FN : Pchar; Const Info : Stat) : Longint;
+Function LinuxToWinAttr (const FN : Ansistring; Const Info : Stat) : Longint;
 
 Var
-  FNL : String;
   LinkInfo : Stat;
 
 begin
   Result:=faArchive;
   If fpS_ISDIR(Info.st_mode) then
     Result:=Result or faDirectory;
-  If (FN[0]='.') and (not (FN[1] in [#0,'.']))  then
+  If (Length(FN)>=2) and
+     (FN[1]='.') and
+     (FN[2]<>'.')  then
     Result:=Result or faHidden;
   If (Info.st_Mode and S_IWUSR)=0 Then
      Result:=Result or faReadOnly;
@@ -562,8 +563,7 @@ begin
     begin
     Result:=Result or faSymLink;
     // Windows reports if the link points to a directory.
-    FNL:=StrPas(FN);
-    if (fpstat(FNL,LinkInfo)>=0) and fpS_ISDIR(LinkInfo.st_mode) then
+    if (fpstat(FN,LinkInfo)>=0) and fpS_ISDIR(LinkInfo.st_mode) then
       Result := Result or faDirectory;
     end;
 end;
@@ -660,8 +660,6 @@ Type
     SearchAttr : Byte;        {attribute we are searching for}
   End;
   PUnixFindData = ^TUnixFindData;
-Var
-  CurrSearchNum : LongInt;
 
 Procedure FindClose(Var f: TSearchRec);
 var
@@ -684,9 +682,7 @@ Function FindGetFileInfo(const s:string;var f:TSearchRec):boolean;
 var
   st           : baseunix.stat;
   WinAttr      : longint;
-  ResolvedPath : string;
-  LinkLen      : ssize_t;
-  
+
 begin
   FindGetFileInfo:=false;
   If Assigned(F.FindHandle) and ((((PUnixFindData(f.FindHandle)^.searchattr)) and faSymlink) > 0) then
@@ -695,7 +691,7 @@ begin
     FindGetFileInfo:=(fpstat(pointer(s),st)=0);
   If not FindGetFileInfo then
     exit;
-  WinAttr:=LinuxToWinAttr(PChar(pointer(s)),st);
+  WinAttr:=LinuxToWinAttr(ExtractFileName(s),st);
   If ((WinAttr and Not(PUnixFindData(f.FindHandle)^.searchattr))=0) Then
    Begin
      f.Name:=ExtractFileName(s);

+ 36 - 0
tests/webtbs/tw14020.pp

@@ -0,0 +1,36 @@
+{ %target=linux,freebsd,darwin,solaris,haiku }
+
+program project1;
+
+uses
+  SysUtils;
+
+var
+  rSearch: TSearchRec;
+  lsName, lsSearch: String;
+  bDone:   Boolean;
+begin
+  { for all files in the dir }
+  lsSearch := './' + AllFilesMask; //fails to find anything
+  WriteLn(lsSearch);
+
+  FillChar(rSearch, Sizeof(TSearchRec), 0);
+  bDone := (FindFirst(lsSearch, 0, rSearch) <> 0);
+
+  while not bDone do
+  begin
+    lsName := rSearch.Name;
+    Assert(lsName <> '');
+    if (rSearch.Attr and faDirectory > 0) then
+      continue;
+
+    { if we find one file, it's ok }
+    findclose(rsearch);
+    halt(0);
+
+    bDone := (FindNext(rSearch) <> 0);
+    Assert(bDone or (rSearch.Name <> lsName));
+  end;
+  FindClose(rSearch);
+  halt(1);
+end.

+ 63 - 0
tests/webtbs/tw14020a.pp

@@ -0,0 +1,63 @@
+{ %target=linux,freebsd,darwin,solaris,haiku }
+
+program project1;
+
+uses
+  SysUtils;
+
+
+procedure cleanup;
+var
+  f: file;
+begin
+  assign(f,'tw14020ad/.hidden');
+  erase(f);
+  rmdir('tw14020ad');
+end;
+
+
+var
+  rSearch: TSearchRec;
+  lsName, lsSearch: String;
+  bDone:   Boolean;
+  f: file;
+begin
+  createdir('tw14020ad');
+  assign(f,'tw14020ad/.hidden');
+  rewrite(f);
+  close(f);
+
+  { for all files in the dir }
+  lsSearch := 'tw14020ad/' + AllFilesMask; //fails to find anything
+
+  FillChar(rSearch, Sizeof(TSearchRec), 0);
+  bDone := (FindFirst(lsSearch, faHidden, rSearch) <> 0);
+
+  while not bDone do
+  begin
+    lsName := rSearch.Name;
+    Assert(lsName <> '');
+    if (rSearch.Attr and faDirectory > 0) then
+      continue;
+
+    { if we find our file, it's ok }
+    if (pos('.hidden',lsName)<>0) then
+      if (rSearch.Attr and faHidden) <> 0 then
+        begin
+          findclose(rsearch);
+          cleanup;
+          halt(0);
+        end
+      else
+        begin
+          findclose(rsearch);
+          cleanup;
+          halt(1);
+        end;
+    bDone := (FindNext(rSearch) <> 0);
+    Assert(bDone or (rSearch.Name <> lsName));
+  end;
+  FindClose(rSearch);
+  cleanup;
+  halt(1);
+end.