What makes me tick.

Friday, November 06, 2009

Mingw stat broken?

I had some unexplained failures in fossil-under-vc-under-dired on windows.  Finally tracked it down to the fact that file_isdir was failing under mingw.   For directory names including the trailing "/", stat does not set the ISDIR flag.  There's some on the topic in http://osdir.com/ml/bug-gnulib-gnu/2009-09/msg00153.html


 int file_isdir(const char *zFilename){
   struct stat buf;
+#ifdef __MINGW32__
+  /* mingw has a bug where a trailing slash causes ISDIR to be zero */
+  Blob  SaneName;
+
+  file_canonical_name(zFilename, &SaneName);
+  if( stat(blob_str(&SaneName), &buf)!=0 ){
+      blob_reset(&SaneName);
+      return 0;
+  }
+  blob_reset(&SaneName);
+#else
   if( stat(zFilename, &buf)!=0 ){
     return 0;
   }
+#endif
   return S_ISDIR(buf.st_mode) ? 1 : 2;
 }

Followers