diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f2843c..e681e5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ - Hardlink (inode) support for several commands and features - Query support for several commands that interact with already seeding torrents +### Bugfix + +- It is now possible to scan single files (again?) #56 + ## [1.3.0] - 2024-02-17 ### Add diff --git a/src/autotorrent/indexer.py b/src/autotorrent/indexer.py index a642b47..f688e55 100644 --- a/src/autotorrent/indexer.py +++ b/src/autotorrent/indexer.py @@ -156,22 +156,28 @@ def _match_ignore_pattern(self, ignore_patterns, p, ignore_case=False): def _scan_path_thread(self, path, queue, root_thread=False): files = [] + def _handle_file(p): + if p.is_dir(): + if self.ignore_directory_patterns and self._match_ignore_pattern( + self.ignore_directory_patterns, Path(p), ignore_case=True + ): + return + self._scan_path_thread(Path(p), queue) + elif p.is_file(): + if self.ignore_file_patterns and self._match_ignore_pattern( + self.ignore_file_patterns, Path(p) + ): + return + files.append(Path(p)) + size = p.stat().st_size + queue.put((IndexAction.ADD, (Path(p), size))) + try: - for p in os.scandir(path): - if p.is_dir(): - if self.ignore_directory_patterns and self._match_ignore_pattern( - self.ignore_directory_patterns, Path(p), ignore_case=True - ): - continue - self._scan_path_thread(Path(p), queue) - elif p.is_file(): - if self.ignore_file_patterns and self._match_ignore_pattern( - self.ignore_file_patterns, Path(p) - ): - continue - files.append(Path(p)) - size = p.stat().st_size - queue.put((IndexAction.ADD, (Path(p), size))) + if path.is_file(): + _handle_file(path) + else: + for p in os.scandir(path): + _handle_file(p) # TODO: probably not utf-8 problems resilient if is_unsplitable(files): # TODO: prevent duplicate work (?) diff --git a/tests/test_cli.py b/tests/test_cli.py index abff1b2..2430fd3 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -239,4 +239,10 @@ def test_cli_add_skip_store_metadata_enabled(testfiles, indexer, matcher, client assert result.exit_code == 0 action, kwargs = client._action_queue[0] assert action == "add" - assert kwargs["destination_path"].name != "data" \ No newline at end of file + assert kwargs["destination_path"].name != "data" + + +def test_cli_scan_single_file(testfiles, indexer, matcher, client, configfile, tmp_path): + runner = CliRunner() + result = runner.invoke(cli, ['scan', '-p', str(testfiles / 'file_b.txt')], catch_exceptions=False) + assert result.exit_code == 0