Skip to content

Commit ca39080

Browse files
committed
Report, if target parent directory does not exist
1 parent 6280226 commit ca39080

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Version 0.4.1 (in development)
22

3+
### Fixes
4+
5+
* If the target _parent_ directory did not exist, an exception was raised
6+
reporting that the lock file to be written does not exist. Changed this to
7+
report that the target parent directory does not exist. [#55]
8+
39
## Version 0.4.0 (from 2024-02-08)
410

511
### Enhancements

tests/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ def test_some_slices_local(self):
5555
for slice_dir in slices:
5656
shutil.rmtree(slice_dir, ignore_errors=True)
5757

58+
def test_some_slices_local_output_to_non_existing_dir(self):
59+
target_dir = "non_existent_dir/target.zarr"
60+
slices = [
61+
"slice-1.zarr",
62+
"slice-2.zarr",
63+
"slice-3.zarr",
64+
]
65+
for uri in slices:
66+
make_test_dataset(uri=uri)
67+
with pytest.raises(
68+
FileNotFoundError,
69+
match="\\ATarget parent directory does not exist: .*/non_existent_dir\\Z",
70+
):
71+
zappend(slices, target_dir=target_dir)
72+
5873
def test_some_slices_with_class_slice_source(self):
5974
target_dir = "memory://target.zarr"
6075
slices = [make_test_dataset(), make_test_dataset(), make_test_dataset()]

zappend/fsutil/transaction.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ def __enter__(self):
115115
)
116116
self._entered_ctx = True
117117

118+
if not self.target_dir.parent.exists():
119+
raise FileNotFoundError(
120+
f"Target parent directory does not exist:"
121+
f" {self.target_dir.parent.path}"
122+
)
123+
118124
lock_file = self._lock_file
119125
if lock_file.exists():
120126
raise OSError(f"Target is locked: {lock_file.uri}")

0 commit comments

Comments
 (0)