diff --git a/lib/api.js b/lib/api.js index bc10a04..3e17b11 100644 --- a/lib/api.js +++ b/lib/api.js @@ -84,11 +84,13 @@ async function cleanTorrentDir({ const { name, files } = parseResult // Get absolute paths of torrent files - const torrentFiles = files.map((file) => path.join(dirPath, file)) + const torrentFiles = files.map((file) => + path.join(dirPath, file).toLowerCase() + ) // Get files not listed in the torrent const extraFiles = dirFiles.filter( - (filename) => torrentFiles.indexOf(filename) === -1 + (filename) => torrentFiles.indexOf(filename.toLowerCase()) === -1 ) if (!dryRun) { diff --git a/lib/config.js b/lib/config.js index c9ecf6e..80b92a2 100644 --- a/lib/config.js +++ b/lib/config.js @@ -79,7 +79,11 @@ exports.loadConfig = async function loadConfig(searchFrom, customConfig) { /** @type {TorrentCleanConfig} */ const mergedConfig = [ // The closer config to `searchFrom` directory is, the higher its priority - ...results.map((result) => result.config).reverse(), + ...results + .filter(Boolean) + // @ts-ignore `.filter(Boolean)` ensures none of `result` below is null + .map((result) => result.config) + .reverse(), customConfig, ] .filter(Boolean) diff --git a/package-lock.json b/package-lock.json index 4db2a78..bb4aa88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@nikolay-borzov/torrent-clean", - "version": "1.7.1", + "version": "1.7.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2330acb..5e4f671 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nikolay-borzov/torrent-clean", - "version": "1.7.1", + "version": "1.7.2", "description": "Deletes files that are not listed in selected torrent file", "keywords": [ "torrent", diff --git a/tests/api.test.js b/tests/api.test.js index ad1dd77..49637eb 100644 --- a/tests/api.test.js +++ b/tests/api.test.js @@ -46,6 +46,9 @@ function createTestDir(tempDirPath) { 'image2.jpg': '[binary]', 'image2 (Copy).jpg': '[binary]', }, + Set3: { + 'image3.jpg': '[binary]', + }, '.edited': { 'image1.jpg': '[binary]', }, @@ -70,7 +73,10 @@ async function createStubTorrent() { const file2 = Buffer.from('[binary]') file2.name = 'set2/image2.jpg' - return createTorrent([file1, file2], { + const file3 = Buffer.from('[binary]') + file3.name = 'set3/image3.jpg' + + return createTorrent([file1, file2, file3], { name: 'Nature Wallpapers', }) } @@ -126,6 +132,21 @@ test('cleanTorrentDir » should clean directory from extra files', async (t) => }) }) +test('cleanTorrentDir » should ignore filename path case', async (t) => { + const { tempDir } = t.context + + const { torrentId, dirPath } = await createTestContext(tempDir.path) + + const expectKept = path.join(dirPath, 'Set3/image3.jpg') + + await cleanTorrentDir({ + torrentId, + dirPath, + }) + + t.true(fs.existsSync(expectKept), `"${expectKept}" should exist`) +}) + test('cleanTorrentDir » should postpone files deleting if `dryRun` is set to `true`', async (t) => { const { tempDir } = t.context