Sfoglia il codice sorgente

cmFileSys.h/c: Symbolic link fixes.

Added kRecurseLInksFsFl and kLinkFsFl.
Changed stat() to lstat() in _cmFileSysIsLink().
Added _cmFileSysIsSocket()
master
kevin 11 anni fa
parent
commit
825a359af2
2 ha cambiato i file con 63 aggiunte e 16 eliminazioni
  1. 51
    6
      cmFileSys.c
  2. 12
    10
      cmFileSys.h

+ 51
- 6
cmFileSys.c Vedi File

@@ -273,7 +273,7 @@ bool _cmFileSysIsLink( cmFs_t* p, const cmChar_t* fnStr )
273 273
   struct stat s;
274 274
   errno = 0;
275 275
 
276
-  if( stat(fnStr,&s)  != 0 )
276
+  if( lstat(fnStr,&s)  != 0 )
277 277
   {
278 278
 
279 279
     // if the file does not exist
@@ -294,6 +294,26 @@ bool cmFileSysIsLink( cmFileSysH_t h, const cmChar_t* fnStr )
294 294
   return _cmFileSysIsLink(p,fnStr);
295 295
 }
296 296
 
297
+bool _cmFileSysIsSocket( cmFs_t* p, const cmChar_t* fnStr )
298
+{
299
+  struct stat s;
300
+  errno = 0;
301
+
302
+  if( stat(fnStr,&s)  != 0 )
303
+  {
304
+
305
+    // if the file does not exist
306
+    if( errno == ENOENT )
307
+      return false;
308
+
309
+    _cmFileSysError( p, kStatFailFsRC, errno, "'stat' failed on '%s'.",fnStr);
310
+    return false;
311
+  }
312
+ 
313
+  return S_ISSOCK(s.st_mode);
314
+}
315
+
316
+
297 317
 bool _cmFileSysConcat( cmChar_t* rp, unsigned rn, char sepChar, const cmChar_t* suffixStr )
298 318
 {
299 319
   unsigned m = strlen(rp);
@@ -777,8 +797,8 @@ typedef struct
777 797
   cmFs_t*              p;
778 798
   unsigned             filterFlags;
779 799
   cmFileSysDirEntry_t* rp;
780
-  cmChar_t*                dataPtr;
781
-  cmChar_t*                endPtr;
800
+  cmChar_t*            dataPtr;
801
+  cmChar_t*            endPtr;
782 802
   unsigned             entryCnt;
783 803
   unsigned             entryIdx;
784 804
   unsigned             dataByteCnt;
@@ -798,6 +818,9 @@ cmFsRC_t _cmFileSysDirGetEntries(  cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
798 818
   if( dirStr == NULL || strlen(dirStr) == 0 )
799 819
     dirStr = curDirPtr;
800 820
 
821
+  if( _cmFileSysIsDir(drp->p,dirStr) == false )
822
+    return rc;
823
+
801 824
   unsigned       fnCharCnt= strlen(dirStr) + PATH_MAX;
802 825
   char           fn[ fnCharCnt + 1 ];
803 826
 
@@ -821,10 +844,10 @@ cmFsRC_t _cmFileSysDirGetEntries(  cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
821 844
   if((dirp = opendir(dirStr)) == NULL)
822 845
   {
823 846
     rc = _cmFileSysError(drp->p,kOpenDirFailFsRC,errno,"Unable to open the directory:'%s'.",dirStr);
847
+
824 848
     goto errLabel;
825 849
   }
826 850
 
827
-
828 851
   // get the next directory entry
829 852
   while((dp = readdir(dirp)) != NULL )
830 853
   {
@@ -873,6 +896,7 @@ cmFsRC_t _cmFileSysDirGetEntries(  cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
873 896
         goto errLabel;
874 897
       }
875 898
 
899
+
876 900
       // is the entry a file
877 901
       if( _cmFileSysIsFile(drp->p,fn) )
878 902
       {
@@ -895,9 +919,27 @@ cmFsRC_t _cmFileSysDirGetEntries(  cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
895 919
             if((rc = _cmFileSysDirGetEntries(drp,fn)) != kOkFsRC )
896 920
               goto errLabel;
897 921
         }
922
+        else
923
+        {
924
+          if( _cmFileSysIsLink(drp->p,fn) )
925
+          {
926
+            if( cmIsFlag(drp->filterFlags,kLinkFsFl) == false )
927
+              continue;
928
+
929
+            flags |= kLinkFsFl;
930
+
931
+            if( cmIsFlag(drp->filterFlags,kRecurseLinksFsFl) )
932
+              if((rc = _cmFileSysDirGetEntries(drp,fn)) != kOkFsRC )
933
+                goto errLabel;
934
+          }
935
+          else
936
+          {
937
+            continue;
938
+          }
939
+        }
898 940
       }
899 941
 
900
-      assert(flags != 0);
942
+      //assert(flags != 0);
901 943
 
902 944
       if( drp->passIdx == 0 )
903 945
       {
@@ -941,6 +983,9 @@ cmFsRC_t _cmFileSysDirGetEntries(  cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
941 983
   }
942 984
 
943 985
  errLabel:
986
+  if( dirp != NULL )
987
+    closedir(dirp);
988
+
944 989
   return rc;
945 990
 }
946 991
 
@@ -962,7 +1007,7 @@ cmFileSysDirEntry_t* cmFileSysDirEntries(  cmFileSysH_t h, const cmChar_t* dirSt
962 1007
     if((rc = _cmFileSysDirGetEntries( &r, dirStr )) != kOkFsRC )
963 1008
       goto errLabel;
964 1009
 
965
-    if( r.passIdx == 0 )
1010
+    if( r.passIdx == 0 && r.dataByteCnt>0 )
966 1011
     {
967 1012
       // allocate memory to hold the return values
968 1013
       if(( r.rp = (cmFileSysDirEntry_t *)cmLHeapAllocZ( r.p->heapH, r.dataByteCnt )) == NULL )

+ 12
- 10
cmFileSys.h Vedi File

@@ -146,16 +146,18 @@ extern "C" {
146 146
   // Flags used by cmFileSysDirEntries 'includeFlags' parameter.
147 147
   enum
148 148
   {
149
-    kFileFsFl      = 0x01,  //< include all visible files
150
-    kDirFsFl       = 0x02,  //< include all visible directory 
151
-    kInvisibleFsFl = 0x04,  //< include file/dir name beginning with a '.'
152
-    kCurDirFsFl    = 0x08,  //< include '.' directory
153
-    kParentDirFsFl = 0x10,  //< include '..' directory
154
-
155
-    kAllFsFl       = 0x1f,  //< all type flags
156
-
157
-    kFullPathFsFl = 0x40, //< return the full path in the 'name' field of cmFileSysDirEntry_t;
158
-    kRecurseFsFl  = 0x80  //< recurse into directories
149
+    kFileFsFl         = 0x001,   //< include all visible files
150
+    kDirFsFl          = 0x002,   //< include all visible directory 
151
+    kLinkFsFl         = 0x004,   //< include all symbolic links
152
+    kInvisibleFsFl    = 0x008,   //< include file/dir name beginning with a '.'
153
+    kCurDirFsFl       = 0x010,   //< include '.' directory
154
+    kParentDirFsFl    = 0x020,   //< include '..' directory
155
+
156
+    kAllFsFl          = 0x02f,   //< all type flags
157
+
158
+    kFullPathFsFl     = 0x040,   //< return the full path in the 'name' field of cmFileSysDirEntry_t;
159
+    kRecurseFsFl      = 0x080,   //< recurse into directories
160
+    kRecurseLinksFsFl = 0x100    //< recurse into symbol link directories 
159 161
 
160 162
   };
161 163
 

Loading…
Annulla
Salva