瀏覽代碼

cmFileSys.h/c: Symbolic link fixes.

Added kRecurseLInksFsFl and kLinkFsFl.
Changed stat() to lstat() in _cmFileSysIsLink().
Added _cmFileSysIsSocket()
master
kevin 11 年之前
父節點
當前提交
825a359af2
共有 2 個文件被更改,包括 63 次插入16 次删除
  1. 51
    6
      cmFileSys.c
  2. 12
    10
      cmFileSys.h

+ 51
- 6
cmFileSys.c 查看文件

273
   struct stat s;
273
   struct stat s;
274
   errno = 0;
274
   errno = 0;
275
 
275
 
276
-  if( stat(fnStr,&s)  != 0 )
276
+  if( lstat(fnStr,&s)  != 0 )
277
   {
277
   {
278
 
278
 
279
     // if the file does not exist
279
     // if the file does not exist
294
   return _cmFileSysIsLink(p,fnStr);
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
 bool _cmFileSysConcat( cmChar_t* rp, unsigned rn, char sepChar, const cmChar_t* suffixStr )
317
 bool _cmFileSysConcat( cmChar_t* rp, unsigned rn, char sepChar, const cmChar_t* suffixStr )
298
 {
318
 {
299
   unsigned m = strlen(rp);
319
   unsigned m = strlen(rp);
777
   cmFs_t*              p;
797
   cmFs_t*              p;
778
   unsigned             filterFlags;
798
   unsigned             filterFlags;
779
   cmFileSysDirEntry_t* rp;
799
   cmFileSysDirEntry_t* rp;
780
-  cmChar_t*                dataPtr;
781
-  cmChar_t*                endPtr;
800
+  cmChar_t*            dataPtr;
801
+  cmChar_t*            endPtr;
782
   unsigned             entryCnt;
802
   unsigned             entryCnt;
783
   unsigned             entryIdx;
803
   unsigned             entryIdx;
784
   unsigned             dataByteCnt;
804
   unsigned             dataByteCnt;
798
   if( dirStr == NULL || strlen(dirStr) == 0 )
818
   if( dirStr == NULL || strlen(dirStr) == 0 )
799
     dirStr = curDirPtr;
819
     dirStr = curDirPtr;
800
 
820
 
821
+  if( _cmFileSysIsDir(drp->p,dirStr) == false )
822
+    return rc;
823
+
801
   unsigned       fnCharCnt= strlen(dirStr) + PATH_MAX;
824
   unsigned       fnCharCnt= strlen(dirStr) + PATH_MAX;
802
   char           fn[ fnCharCnt + 1 ];
825
   char           fn[ fnCharCnt + 1 ];
803
 
826
 
821
   if((dirp = opendir(dirStr)) == NULL)
844
   if((dirp = opendir(dirStr)) == NULL)
822
   {
845
   {
823
     rc = _cmFileSysError(drp->p,kOpenDirFailFsRC,errno,"Unable to open the directory:'%s'.",dirStr);
846
     rc = _cmFileSysError(drp->p,kOpenDirFailFsRC,errno,"Unable to open the directory:'%s'.",dirStr);
847
+
824
     goto errLabel;
848
     goto errLabel;
825
   }
849
   }
826
 
850
 
827
-
828
   // get the next directory entry
851
   // get the next directory entry
829
   while((dp = readdir(dirp)) != NULL )
852
   while((dp = readdir(dirp)) != NULL )
830
   {
853
   {
873
         goto errLabel;
896
         goto errLabel;
874
       }
897
       }
875
 
898
 
899
+
876
       // is the entry a file
900
       // is the entry a file
877
       if( _cmFileSysIsFile(drp->p,fn) )
901
       if( _cmFileSysIsFile(drp->p,fn) )
878
       {
902
       {
895
             if((rc = _cmFileSysDirGetEntries(drp,fn)) != kOkFsRC )
919
             if((rc = _cmFileSysDirGetEntries(drp,fn)) != kOkFsRC )
896
               goto errLabel;
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
       if( drp->passIdx == 0 )
944
       if( drp->passIdx == 0 )
903
       {
945
       {
941
   }
983
   }
942
 
984
 
943
  errLabel:
985
  errLabel:
986
+  if( dirp != NULL )
987
+    closedir(dirp);
988
+
944
   return rc;
989
   return rc;
945
 }
990
 }
946
 
991
 
962
     if((rc = _cmFileSysDirGetEntries( &r, dirStr )) != kOkFsRC )
1007
     if((rc = _cmFileSysDirGetEntries( &r, dirStr )) != kOkFsRC )
963
       goto errLabel;
1008
       goto errLabel;
964
 
1009
 
965
-    if( r.passIdx == 0 )
1010
+    if( r.passIdx == 0 && r.dataByteCnt>0 )
966
     {
1011
     {
967
       // allocate memory to hold the return values
1012
       // allocate memory to hold the return values
968
       if(( r.rp = (cmFileSysDirEntry_t *)cmLHeapAllocZ( r.p->heapH, r.dataByteCnt )) == NULL )
1013
       if(( r.rp = (cmFileSysDirEntry_t *)cmLHeapAllocZ( r.p->heapH, r.dataByteCnt )) == NULL )

+ 12
- 10
cmFileSys.h 查看文件

146
   // Flags used by cmFileSysDirEntries 'includeFlags' parameter.
146
   // Flags used by cmFileSysDirEntries 'includeFlags' parameter.
147
   enum
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…
取消
儲存