diff --git a/src/CSET/cset_workflow/app/fetch_fcst/bin/fetch_data.py b/src/CSET/cset_workflow/app/fetch_fcst/bin/fetch_data.py index acf999a7c..fb5453b98 100644 --- a/src/CSET/cset_workflow/app/fetch_fcst/bin/fetch_data.py +++ b/src/CSET/cset_workflow/app/fetch_fcst/bin/fetch_data.py @@ -110,10 +110,13 @@ def get_file(self, file_path: str, output_dir: str) -> bool: logging.warning("file_path does not match any files: %s", file_path) any_files_copied = False for f in file_paths: - file = Path(f) + file = Path(f).absolute() try: - # We know file exists from glob. - os.symlink(file.absolute(), f"{output_dir}/{file.name}") + # Save to a filename derived from the full path, to + # differentiate similarly named files from different + # directories. + # `)` replaces `/` as it can be in file names. + os.symlink(file, f"{output_dir}/{')'.join(file.parts)}") any_files_copied = True except OSError as err: logging.warning("Failed to copy %s, error: %s", file, err) diff --git a/tests/workflow_utils/test_fetch_data.py b/tests/workflow_utils/test_fetch_data.py index f9415bcf5..50574b53c 100644 --- a/tests/workflow_utils/test_fetch_data.py +++ b/tests/workflow_utils/test_fetch_data.py @@ -237,10 +237,10 @@ def test_FilesystemFileRetriever(tmp_path): # Correct return value. assert files_found # Symlinks created. - assert (tmp_path / "exeter_em01.nc").exists(follow_symlinks=False) - assert (tmp_path / "exeter_em02.nc").exists(follow_symlinks=False) + retrieved_files = sorted(tmp_path.glob("*exeter_em0?.nc")) + assert len(retrieved_files) == 2 # Check symlink points to correct file. - with open((tmp_path / "exeter_em01.nc"), "rb") as fp: + with open(retrieved_files[0], "rb") as fp: digest = hashlib.file_digest(fp, "sha256").hexdigest() assert digest == "23761fd2456b2dbbb18f35fa4909561569af0851ebda6e3705e70e366c86ac09"