fix(memory): skip OpenViking upload symlinks

This commit is contained in:
binhnt92 2026-05-12 12:45:26 +07:00 committed by Teknium
parent 26deeea830
commit 63991bbd97
2 changed files with 45 additions and 0 deletions

View file

@ -336,10 +336,17 @@ ADD_RESOURCE_SCHEMA = {
def _zip_directory(dir_path: Path) -> Path:
"""Create a temporary zip file containing a directory tree."""
root = dir_path.resolve()
zip_path = Path(tempfile.gettempdir()) / f"openviking_upload_{uuid.uuid4().hex}.zip"
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
for file_path in dir_path.rglob("*"):
if file_path.is_symlink():
continue
if file_path.is_file():
try:
file_path.resolve().relative_to(root)
except ValueError:
continue
arcname = str(file_path.relative_to(dir_path)).replace("\\", "/")
zipf.write(file_path, arcname=arcname)
return zip_path