about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2009-01-08 21:51:26 +0100
committerRichard Nyberg <rnyberg@murmeldjur.se>2009-01-11 00:37:00 +0100
commit4457c1268a923d2a662ab23ca1b8d7920811ae51 (patch)
treeb42451e47cf2913d5ff23d11f08b81fb34967770
parentb5d78b066a2da696eca1e321cdb4a53dd3557843 (diff)
downloadbtpd-4457c1268a923d2a662ab23ca1b8d7920811ae51.tar.gz
btpd-4457c1268a923d2a662ab23ca1b8d7920811ae51.zip
Let btpd remove torrent data by itself instead of calling rm.
-rw-r--r--btpd/tlib.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/btpd/tlib.c b/btpd/tlib.c
index 362139d..e68c341 100644
--- a/btpd/tlib.c
+++ b/btpd/tlib.c
@@ -62,11 +62,22 @@ int
 tlib_del(struct tlib *tl)
 {
     char relpath[RELPATH_SIZE];
-    char cmd[PATH_MAX];
+    char path[PATH_MAX];
+    DIR *dir;
+    struct dirent *de;
     assert(tl->tp == NULL);
-    snprintf(cmd, PATH_MAX, "rm -r torrents/%s",
-        bin2hex(tl->hash, relpath, 20));
-    system(cmd);
+    snprintf(path, PATH_MAX, "torrents/%s", bin2hex(tl->hash, relpath, 20));
+    if ((dir = opendir(path)) != NULL) {
+        while ((de = readdir(dir)) != NULL) {
+            if (strcmp(".", de->d_name) == 0 || strcmp("..", de->d_name) == 0)
+                continue;
+            snprintf(path, PATH_MAX, "torrents/%s/%s", relpath, de->d_name);
+            remove(path);
+        }
+        closedir(dir);
+    }
+    snprintf(path, PATH_MAX, "torrents/%s", relpath);
+    remove(path);
     tlib_kill(tl);
     return 0;
 }