diff --git a/antarest/matrixstore/repository.py b/antarest/matrixstore/repository.py index ee6fefabea..03d8f65b93 100644 --- a/antarest/matrixstore/repository.py +++ b/antarest/matrixstore/repository.py @@ -229,9 +229,7 @@ def save(self, content: t.Union[t.List[t.List[MatrixData]], npt.NDArray[np.float # Avoid having to save the matrix again (that's the whole point of using a hash). return matrix_hash - lock_file = matrix_path.parent.joinpath( - f"{matrix_hash}.tsv.lock" - ) # use tsv lock to stay consistent with old data + lock_file = matrix_path.with_suffix(".tsv.lock") # use tsv lock to stay consistent with old data for internal_format in InternalMatrixFormat: matrix_in_another_format_path = self.bucket_dir.joinpath(f"{matrix_hash}.{internal_format}") if matrix_in_another_format_path.exists(): @@ -282,5 +280,5 @@ def delete(self, matrix_hash: str) -> None: # IMPORTANT: Deleting the lock file under Linux can make locking unreliable. # Abandoned lock files are deleted here to maintain consistent behavior. - lock_file = matrix_path.parent.joinpath(f"{matrix_hash}.tsv.lock") + lock_file = matrix_path.with_suffix(".tsv.lock") lock_file.unlink(missing_ok=True) diff --git a/tests/matrixstore/test_repository.py b/tests/matrixstore/test_repository.py index d63f63cbec..621f624e9b 100644 --- a/tests/matrixstore/test_repository.py +++ b/tests/matrixstore/test_repository.py @@ -304,7 +304,7 @@ def test_mixed_formats(self, tmp_path: str, matrix_format: str) -> None: associated_hash = "d73f023a3f852bf2e5c6d836cd36cd930d0091dcba7f778161c707e1c58222b0" matrix_path = matrix_content_repo.bucket_dir.joinpath(f"{associated_hash}.{saved_format}") saved_format.save_matrix(df, matrix_path) - lock_path = matrix_content_repo.bucket_dir.joinpath(f"{associated_hash}.tsv.lock") + lock_path = matrix_path.with_suffix(".tsv.lock") lock_path.touch() # asserts the saved matrix object exists @@ -331,5 +331,5 @@ def test_mixed_formats(self, tmp_path: str, matrix_format: str) -> None: assert not saved_matrix_files repo_matrix_files = list(matrix_content_repo.bucket_dir.glob(f"*.{repository_format}")) assert len(repo_matrix_files) == 1 - new_matrix_path = matrix_content_repo.bucket_dir.joinpath(f"{associated_hash}.{repository_format}") + new_matrix_path = matrix_content_repo.bucket_dir.with_suffix(f".{repository_format}") assert repo_matrix_files[0] == new_matrix_path