Merge pull request #796 from OMEGARAZER/empty-dir-fix
This commit is contained in:
commit
6df7906818
2 changed files with 16 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue