Skip to content

Commit 6249c79

Browse files
committed
cleaning input path to account for ending '/' as well as 'incoming'
1 parent a6e83c7 commit 6249c79

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

mokelumne/dags/copy_files.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from mokelumne.util.storage import run_dir
1515
from mokelumne.util.file_transfer import (
1616
build_file_manifest,
17+
clean_destination_path,
1718
copy_files_from_manifest,
1819
load_json,
1920
save_json,
@@ -76,7 +77,7 @@ def prepare_destination() -> str:
7677

7778
ctx = get_current_context()
7879
destination = ctx["params"]["destination"]
79-
80+
destination = clean_destination_path(destination)
8081
destination_path = Path(destination)
8182

8283
if not destination_path.exists():

mokelumne/util/file_transfer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import hashlib
44
import json
5+
import re
56
import shutil
67

78
from pathlib import Path
@@ -64,6 +65,11 @@ def load_json(path: Path) -> Manifest:
6465
with open(path, "r", encoding="utf-8") as json_file:
6566
return json.load(json_file)
6667

68+
def clean_destination_path(destination_path: str) -> str:
69+
clean_path = re.sub(r'/incoming$|/incoming/$|/$', '', destination_path)
70+
clean_path = clean_path + '/incoming'
71+
72+
return clean_path
6773

6874
def verify_file_manifest(destination_path: Path, manifest_path: Path) -> list[ManifestEntry]:
6975
"""Verify all copied files exist at the destination."""

test/unit/test_file_transfer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ def test_build_manifest_excludes_hidden_and_excluded_files(self, tmp_path: Path)
9595
assert paths == {"visible.tif"}
9696
assert len(result["files"]) == 1
9797

98+
@pytest.mark.parametrize(
99+
("input_path", "expected_path"),
100+
[
101+
("/srv/pa/aerial/ucb", "/srv/pa/aerial/ucb/incoming"),
102+
("/srv/pa/aerial/ucb/", "/srv/pa/aerial/ucb/incoming"),
103+
("/srv/pa/aerial/ucb/incoming", "/srv/pa/aerial/ucb/incoming"),
104+
("/srv/pa/aerial/ucb/incoming/", "/srv/pa/aerial/ucb/incoming"),
105+
],
106+
)
107+
def test_clean_destination_path(self, input_path: str, expected_path: str):
108+
"""Ensure clean_destination_path normalizes the incoming directory suffix."""
109+
110+
assert file_transfer.clean_destination_path(input_path) == expected_path
111+
98112
def test_verify_manifest_success(self, tmp_path: Path):
99113
"""Ensure verify_manifest succeeds for valid files."""
100114

0 commit comments

Comments
 (0)