Skip to content

Commit 734631b

Browse files
🐛 [-bug] Addressed issue encountered when attempting to restore dups (#14)
2 parents 639e3f4 + 7c3210c commit 734631b

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

src/FileBackup/Offsite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,9 @@ def PathToFilename(
864864
directory_working_dir
865865
)
866866

867-
dest_filename.parent.mkdir(parents=True, exist_ok=True)
868-
869-
os.symlink(fullpath, dest_filename)
867+
if not dest_filename.is_file():
868+
dest_filename.parent.mkdir(parents=True, exist_ok=True)
869+
os.symlink(fullpath, dest_filename)
870870

871871
# Read the instructions
872872
with (directory_working_dir / INDEX_FILENAME).open() as f:

tests/Offsite_UnitTest.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,49 @@ def test_DryRun(self, _working_dir, tmp_path_factory):
11111111
sep=os.path.sep,
11121112
)
11131113

1114+
# ----------------------------------------------------------------------
1115+
@pytest.mark.parametrize("is_local_filesystem", [True, False])
1116+
@pytest.mark.parametrize("encryption_password", [None, str(uuid.uuid4())])
1117+
@pytest.mark.parametrize("compress", [False, True])
1118+
def test_RestoreMultipleBackupsSameFile(
1119+
self, _working_dir, tmp_path_factory, compress, encryption_password, is_local_filesystem
1120+
):
1121+
with _YieldInitializedBackupHelper(
1122+
tmp_path_factory, _working_dir, compress, encryption_password
1123+
) as backup_helper:
1124+
restore_helper = _RestoreHelper.Create(
1125+
_working_dir,
1126+
tmp_path_factory,
1127+
encryption_password,
1128+
is_local_filesystem,
1129+
backup_helper.backup_name,
1130+
backup_helper.output_dir,
1131+
)
1132+
1133+
# Read the contents of a file. We will remove this file, create a backup, and then
1134+
# restore the same file.
1135+
file_under_test = _working_dir / "one" / "A"
1136+
assert file_under_test.is_file(), file_under_test
1137+
1138+
file_under_test_contents = file_under_test.read_text(encoding="utf-8")
1139+
1140+
backup_file_under_test = restore_helper.backup_dir / "one" / "A"
1141+
1142+
# Remove the file
1143+
file_under_test.unlink()
1144+
1145+
backup_helper.ExecuteBackup(_working_dir, compress, encryption_password)
1146+
1147+
# Write the file
1148+
file_under_test.write_text(file_under_test_contents, encoding="utf-8")
1149+
1150+
backup_helper.ExecuteBackup(_working_dir, compress, encryption_password)
1151+
1152+
# Restore the backup
1153+
restore_helper.ExecuteRestore(10)
1154+
1155+
assert Path(restore_helper.output_dir / "one" / "A").is_file()
1156+
11141157

11151158
# ----------------------------------------------------------------------
11161159
class TestRestoreErrors:
@@ -1487,7 +1530,7 @@ def ExecuteRestore(
14871530

14881531
output = cast(str, next(dm_and_content))
14891532

1490-
assert dm.result == expected_result
1533+
assert dm.result == expected_result, output
14911534

14921535
if expected_num_files is not None:
14931536
TestHelpers.CompareFileSystemSourceAndDestination(

0 commit comments

Comments
 (0)