Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/CSET/cset_workflow/app/fetch_fcst/bin/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/workflow_utils/test_fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading