1
0
Fork 0
mirror of synced 2024-10-01 17:47:46 +13:00

Merge pull request #796 from OMEGARAZER/empty-dir-fix

This commit is contained in:
Serene 2023-02-27 17:25:40 +10:00 committed by GitHub
commit 6df7906818
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -123,12 +123,12 @@ class RedditDownloader(RedditConnector):
)
return
resource_hash = res.hash.hexdigest()
destination.parent.mkdir(parents=True, exist_ok=True)
if resource_hash in self.master_hash_list:
if self.args.no_dupes:
logger.info(f"Resource hash {resource_hash} from submission {submission.id} downloaded elsewhere")
return
elif self.args.make_hard_links:
destination.parent.mkdir(parents=True, exist_ok=True)
try:
destination.hardlink_to(self.master_hash_list[resource_hash])
except AttributeError:
@ -138,6 +138,7 @@ class RedditDownloader(RedditConnector):
f" in submission {submission.id}"
)
return
destination.parent.mkdir(parents=True, exist_ok=True)
try:
with destination.open("wb") as file:
file.write(res.content)

View file

@ -439,3 +439,17 @@ def test_cli_download_explicit_filename_restriction_scheme(test_args: list[str],
assert result.exit_code == 0
assert "Downloaded submission" in result.output
assert "Forcing Windows-compatible filenames" in result.output
@pytest.mark.online
@pytest.mark.reddit
@pytest.mark.skipif(not does_test_config_exist, reason="A test config file is required for integration tests")
@pytest.mark.parametrize("test_args", (["--link", "ehqt2g", "--link", "ehtuv8", "--no-dupes"],))
def test_cli_download_no_empty_dirs(test_args: list[str], tmp_path: Path):
runner = CliRunner()
test_args = create_basic_args_for_download_runner(test_args, tmp_path)
result = runner.invoke(cli, test_args)
assert result.exit_code == 0
assert "downloaded elsewhere" in result.output
assert Path(tmp_path, "EmpireDidNothingWrong").exists()
assert not Path(tmp_path, "StarWarsEU").exists()