Ejemplo n.º 1
0
def test_detect_corrupt_new(test_dataset: DatasetForTests,
                            integration_test_data: Path):
    # type: (Tuple[Collection, str, str, Path]) -> None
    """If a dataset exists but cannot be read handle as corrupt"""

    path = uri_to_local_path(test_dataset.uri)

    # Write corrupted file.
    os.unlink(str(path))
    with path.open('w') as f:
        f.write('corruption!')
    assert path.exists()

    # No dataset in index at the corrupt location, so it should be trashed.
    _check_sync(
        collection=test_dataset.collection,
        expected_paths=[test_dataset.uri],
        expected_mismatches=[
            mm.UnreadableDataset(None, test_dataset.uri)
        ],
        expected_index_result={},
        cache_path=integration_test_data,
        fix_settings=dict(trash_missing=True, trash_archived=True, update_locations=True)
    )
    assert not path.exists(), "Corrupt dataset without sibling should be trashed with trash_archived=True"
Ejemplo n.º 2
0
def test_detect_corrupt_existing(test_dataset: DatasetForTests,
                                 integration_test_data: Path):
    # type: (Tuple[Collection, str, str, Path]) -> None
    """If a dataset exists but cannot be read, report as corrupt"""
    path = uri_to_local_path(test_dataset.uri)

    test_dataset.add_to_index()
    assert path.exists()

    # Overwrite with corrupted file.
    os.unlink(str(path))
    with path.open('w') as f:
        f.write('corruption!')
    assert path.exists()

    # Another dataset exists in the same location

    _check_sync(
        collection=test_dataset.collection,
        expected_paths=[test_dataset.uri],
        expected_mismatches=[
            # We don't know if it's the same dataset
            mm.UnreadableDataset(None, test_dataset.uri)
        ],
        # Unmodified index
        expected_index_result=freeze_index(test_dataset.collection.index_),
        cache_path=integration_test_data,
        fix_settings=dict(trash_missing=True, trash_archived=True, update_locations=True)
    )
    # If a dataset is in the index pointing to the corrupt location, it shouldn't be trashed with trash_archived=True
    assert path.exists(), "Corrupt dataset with sibling in index should not be trashed"