about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-10-15 15:31:17 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-10-15 15:31:17 +0000
commit1a17b22bb3cd80312dfee2e6421fd934b70dd24c (patch)
treef36f500d64415249d46aa85f6768e45924048513
parentcd8a3d5ecd87c3977dad347c9683b6f3cb37532f (diff)
downloadbtpd-1a17b22bb3cd80312dfee2e6421fd934b70dd24c.tar.gz
btpd-1a17b22bb3cd80312dfee2e6421fd934b70dd24c.zip
Don't call mkdirs unnecessarily. Note that this code is only needed because
the content code shuts down btpd on errors. When that is fixed this code can
be removed.

-rw-r--r--btpd/torrent.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/btpd/torrent.c b/btpd/torrent.c
index c7bd33f..9a2be5c 100644
--- a/btpd/torrent.c
+++ b/btpd/torrent.c
@@ -95,16 +95,24 @@ torrent_start(struct tlib *tl)
     if (tl->dir == NULL)
         return IPC_EBADTENT;
 
-    if (mkdirs(tl->dir, 0777) != 0 && errno != EEXIST) {
-        btpd_log(BTPD_L_ERROR, "torrent '%s': "
-            "failed to create content dir '%s' (%s).\n",
-            tl->name, tl->dir, strerror(errno));
-        return IPC_ECREATECDIR;
-    } else if (stat(tl->dir, &sb) == -1 ||
-            ((sb.st_mode & S_IFMT) != S_IFDIR)) {
+    if (stat(tl->dir, &sb) == 0) {
+        if ((sb.st_mode & S_IFMT) != S_IFDIR) {
+            btpd_log(BTPD_L_ERROR,
+                "torrent '%s': content dir '%s' is not a directory\n",
+                tl->name, tl->dir);
+            return IPC_EBADCDIR;
+        }
+    } else if (errno == ENOENT) {
+        if (mkdirs(tl->dir, 0777) != 0 && errno != EEXIST) {
+            btpd_log(BTPD_L_ERROR, "torrent '%s': "
+                "failed to create content dir '%s' (%s).\n",
+                tl->name, tl->dir, strerror(errno));
+            return IPC_ECREATECDIR;
+        }
+    } else {
         btpd_log(BTPD_L_ERROR,
-            "torrent '%s': content dir '%s' is either not a directory or"
-            " cannot be accessed.\n", tl->name, tl->dir);
+            "torrent '%s': couldn't stat content dir '%s' (%s)\n",
+            tl->name, tl->dir, strerror(errno));
         return IPC_EBADCDIR;
     }