From 2e0de5252090ab576761c7cd8cef5ce751ffb8e5 Mon Sep 17 00:00:00 2001 From: DC Date: Fri, 13 May 2016 15:18:08 -0700 Subject: [PATCH] Fix torrentPath migration (#479) Fixes #448 --- renderer/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/renderer/index.js b/renderer/index.js index 90ee2877..55b145f4 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -114,10 +114,19 @@ function cleanUpConfig () { // Migration: replace torrentPath with torrentFileName var src, dst if (ts.torrentPath) { + // There are a number of cases to handle here: + // * Originally we used absolute paths + // * Then, relative paths for the default torrents, eg '../static/sintel.torrent' + // * Then, paths computed at runtime for default torrents, eg 'sintel.torrent' + // * Finally, now we're getting rid of torrentPath altogether console.log('migration: replacing torrentPath %s', ts.torrentPath) - src = path.isAbsolute(ts.torrentPath) - ? ts.torrentPath - : path.join(config.STATIC_PATH, ts.torrentPath) + if (path.isAbsolute(ts.torrentPath)) { + src = ts.torrentPath + } else if (ts.torrentPath.startsWith('..')) { + src = ts.torrentPath + } else { + src = path.join(config.STATIC_PATH, ts.torrentPath) + } dst = path.join(config.CONFIG_TORRENT_PATH, infoHash + '.torrent') // Synchronous FS calls aren't ideal, but probably OK in a migration // that only runs once