[or-cvs] Make check_private_dir trimodal (check/create/ignore), not ...

Nick Mathewson nickm at seul.org
Tue Nov 9 07:12:33 UTC 2004


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv16513/src/common

Modified Files:
	util.c util.h 
Log Message:
Make check_private_dir trimodal (check/create/ignore), not bimodal (create/ignore).

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -d -r1.171 -r1.172
--- util.c	9 Nov 2004 01:24:10 -0000	1.171
+++ util.c	9 Nov 2004 07:12:31 -0000	1.172
@@ -701,9 +701,11 @@
 }
 
 /** Check whether dirname exists and is private.  If yes return 0.  If
- * it does not exist, and create is set, try to create it and return 0
- * on success.  Else return -1. */
-int check_private_dir(const char *dirname, int create)
+ * it does not exist, and check==CPD_CREATE is set, try to create it
+ * and return 0 on success. If it does not exist, and
+ * check==CPD_CHECK, and we think we can create it, return 0.  Else
+ * return -1. */
+int check_private_dir(const char *dirname, cpd_check_t check)
 {
   int r;
   struct stat st;
@@ -714,23 +716,26 @@
           strerror(errno));
       return -1;
     }
-    if (!create) {
+    if (check == CPD_NONE) {
       log(LOG_WARN, "Directory %s does not exist.", dirname);
       return -1;
-    }
-    log(LOG_INFO, "Creating directory %s", dirname);
+    } else if (check == CPD_CREATE) {
+      log(LOG_INFO, "Creating directory %s", dirname);
 #ifdef MS_WINDOWS
-    r = mkdir(dirname);
+      r = mkdir(dirname);
 #else
-    r = mkdir(dirname, 0700);
+      r = mkdir(dirname, 0700);
 #endif
-    if (r) {
-      log(LOG_WARN, "Error creating directory %s: %s", dirname,
-          strerror(errno));
-      return -1;
-    } else {
-      return 0;
+      if (r) {
+        log(LOG_WARN, "Error creating directory %s: %s", dirname,
+            strerror(errno));
+        return -1;
+      }
     }
+
+    /* XXXX In the case where check==CPD_CHECK, we should look at the
+     * parent directory a little harder. */
+    return 0;
   }
   if (!(st.st_mode & S_IFDIR)) {
     log(LOG_WARN, "%s is not a directory", dirname);

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- util.h	6 Nov 2004 05:18:29 -0000	1.116
+++ util.h	9 Nov 2004 07:12:31 -0000	1.117
@@ -88,7 +88,8 @@
 typedef enum { FN_ERROR, FN_NOENT, FN_FILE, FN_DIR} file_status_t;
 file_status_t file_status(const char *filename);
 
-int check_private_dir(const char *dirname, int create);
+typedef enum { CPD_NONE, CPD_CREATE, CPD_CHECK } cpd_check_t;
+int check_private_dir(const char *dirname, cpd_check_t check);
 int write_str_to_file(const char *fname, const char *str, int bin);
 int write_bytes_to_file(const char *fname, const char *str, size_t len,
                         int bin);



More information about the tor-commits mailing list