From db4e9b869d0434dbb621a7dcc87e06e8c7beb727 Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Sun, 27 Nov 2005 12:18:44 +0000 Subject: [PATCH] This is very much a intermediate commit. * Load "test" torrent on start. * Look for content and resume in the right places. --- btpd/main.c | 1 + btpd/policy_subr.c | 4 ++-- btpd/torrent.c | 15 +++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/btpd/main.c b/btpd/main.c index 8c75a3d..d9f57a2 100644 --- a/btpd/main.c +++ b/btpd/main.c @@ -174,6 +174,7 @@ args_done: event_init(); btpd_init(); + torrent_load("test"); event_dispatch(); btpd_err("Unexpected exit from libevent.\n"); diff --git a/btpd/policy_subr.c b/btpd/policy_subr.c index 5683ed8..5ef26fe 100644 --- a/btpd/policy_subr.c +++ b/btpd/policy_subr.c @@ -206,7 +206,7 @@ test_hash(struct torrent *tp, uint8_t *hash, unsigned long index) int bufi; int err; - err = vopen(&fd, O_RDONLY, "%s", tp->relpath); + err = vopen(&fd, O_RDONLY, "%s/torrent", tp->relpath); if (err != 0) btpd_err("test_hash: %s\n", strerror(err)); @@ -231,7 +231,7 @@ static int ro_fd_cb(const char *path, int *fd, void *arg) { struct torrent *tp = arg; - return vopen(fd, O_RDONLY, "%s.d/%s", tp->relpath, path); + return vopen(fd, O_RDONLY, "%s/content/%s", tp->relpath, path); } static void diff --git a/btpd/torrent.c b/btpd/torrent.c index 6fe5a35..0737f6b 100644 --- a/btpd/torrent.c +++ b/btpd/torrent.c @@ -23,14 +23,14 @@ static int ro_fd_cb(const char *path, int *fd, void *arg) { struct torrent *tp = arg; - return vopen(fd, O_RDONLY, "%s.d/%s", tp->relpath, path); + return vopen(fd, O_RDONLY, "%s/content/%s", tp->relpath, path); } static int wo_fd_cb(const char *path, int *fd, void *arg) { struct torrent *tp = arg; - return vopen(fd, O_WRONLY|O_CREAT, "%s.d/%s", tp->relpath, path); + return vopen(fd, O_WRONLY|O_CREAT, "%s/content/%s", tp->relpath, path); } static int @@ -70,14 +70,15 @@ torrent_load3(const char *file, struct metainfo *mi, char *mem, size_t memsiz) } static int -torrent_load2(const char *file, struct metainfo *mi) +torrent_load2(const char *name, struct metainfo *mi) { int error, ifd; struct stat sb; char *mem; size_t memsiz; + const char *file = name; - if ((error = vopen(&ifd, O_RDWR, "%s.i", file)) != 0) { + if ((error = vopen(&ifd, O_RDWR, "%s/resume", file)) != 0) { btpd_log(BTPD_L_ERROR, "Error opening %s.i: %s.\n", file, strerror(error)); return error; @@ -116,10 +117,12 @@ torrent_load2(const char *file, struct metainfo *mi) } int -torrent_load(const char *file) +torrent_load(const char *name) { struct metainfo *mi; int error; + char file[PATH_MAX]; + snprintf(file, PATH_MAX, "%s/torrent", name); if ((error = load_metainfo(file, -1, 0, &mi)) != 0) { btpd_log(BTPD_L_ERROR, "Couldn't load metainfo file %s: %s.\n", @@ -133,7 +136,7 @@ torrent_load(const char *file) } if (error == 0) - error = torrent_load2(file, mi); + error = torrent_load2(name, mi); if (error != 0) { clear_metainfo(mi);