Commits

Greg Ward committed 63afae8

Make probe for CVS more picky: CVS/Entries must be a file.
This is mainly because I keep getting strange results on OS X
with a case-insensitive filesystem, where the tests create
a "cvs" subdirectory which fools the simple isdir("CVS") probe.

  • Participants
  • Parent commits c238324

Comments (0)

Files changed (4)

File src/common.c

     va_end(args);
 }
 
-int isdir(char* name)
+static int _testmode(char* name, mode_t bits, char what[])
 {
     struct stat statbuf;
     if (stat(name, &statbuf) < 0) {
         debug("failed to stat() '%s': %s", name, strerror(errno));
         return 0;
     }
-    if (!S_ISDIR(statbuf.st_mode)) {
-        debug("'%s' not a directory", name);
-        return 0;
+    if ((statbuf.st_mode & bits) == 0) {
+        debug("'%s' not a %s", name, what);
+	return 0;
     }
     return 1;
 }
 
+int isdir(char* name)
+{
+    return _testmode(name, S_IFDIR, "directory");
+}
+
+int isfile(char* name)
+{
+    return _testmode(name, S_IFREG, "regular file");
+}
+
 int read_first_line(char* filename, char* buf, int size)
 {
     FILE* file;

File src/common.h

 void debug(char*, ...);
 
 int isdir(char*);
+int isfile(char*);
 int read_first_line(char*, char*, int);
 int read_last_line(char*, char*, int);
 int read_file(const char*, char*, int);
 static int
 cvs_probe(vccontext_t* context)
 {
-    return isdir("CVS");
+    return isfile("CVS/Entries");
 }
 
 static result_t*

File tests/test-simple

 {
     cd $tmpdir
     mkdir cvs && cd cvs
-    mkdir CVS
+    mkdir CVS && touch CVS/Entries
 
     assert_vcprompt "cvs notag" "cvs:trunk" "%n:%b"
 
     mkdir build && cd build
     assert_vcprompt "cvs subdir 1" "foo"
 
-    mkdir CVS
+    mkdir CVS && touch CVS/Entries
     echo "Tblah" > CVS/Tag
     assert_vcprompt "cvs subdir 2" "blah"
 }