mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-09-15 00:19:14 +00:00
fix: preserve missing-upload delete contract
This commit is contained in:
parent
8a3cb391f6
commit
e818efc9e8
@ -387,7 +387,12 @@ def delete_file_safe(base_dir: Path, filename: str) -> dict:
|
||||
safe_name = normalize_filename(filename)
|
||||
if safe_name != filename:
|
||||
raise PathTraversalError("Path traversal detected")
|
||||
base_dir = _validate_upload_directory(Path(base_dir))
|
||||
try:
|
||||
base_dir = _validate_upload_directory(Path(base_dir))
|
||||
except UnsafeUploadPathError as exc:
|
||||
if isinstance(exc.__cause__, FileNotFoundError):
|
||||
raise FileNotFoundError(f"File not found: {filename}") from exc
|
||||
raise
|
||||
file_path = base_dir / safe_name
|
||||
try:
|
||||
file_stat = os.lstat(file_path)
|
||||
|
||||
@ -362,6 +362,10 @@ class TestDeleteFileSafe:
|
||||
with pytest.raises(FileNotFoundError):
|
||||
delete_file_safe(tmp_path, "nope.txt")
|
||||
|
||||
def test_delete_from_nonexistent_directory_raises_file_not_found(self, tmp_path):
|
||||
with pytest.raises(FileNotFoundError, match="ghost.txt"):
|
||||
delete_file_safe(tmp_path / "missing-uploads", "ghost.txt")
|
||||
|
||||
def test_delete_traversal_raises(self, tmp_path):
|
||||
with pytest.raises(PathTraversalError, match="traversal"):
|
||||
delete_file_safe(tmp_path, "../outside.txt")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user