summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-11-09 07:12:31 +0000
committerNick Mathewson <nickm@torproject.org>2004-11-09 07:12:31 +0000
commit180e0a9326a1383cf3a945e84700f99f5f9e4df1 (patch)
tree1839878e30f80d127ef798159b227add6200259c /src/common
parent6521c2ce51b3b808dd8ef5c47dc9995acce149e5 (diff)
downloadtor-180e0a9326a1383cf3a945e84700f99f5f9e4df1.tar.gz
tor-180e0a9326a1383cf3a945e84700f99f5f9e4df1.zip
Make check_private_dir trimodal (check/create/ignore), not bimodal (create/ignore).
svn:r2733
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c33
-rw-r--r--src/common/util.h3
2 files changed, 21 insertions, 15 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 292b7cfd5b..8311f95be5 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -701,9 +701,11 @@ file_status_t file_status(const char *fname)
}
/** 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 @@ int check_private_dir(const char *dirname, int create)
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);
diff --git a/src/common/util.h b/src/common/util.h
index c925834daf..9f116b5796 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -88,7 +88,8 @@ int read_all(int fd, char *buf, size_t count, int isSocket);
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);