From 0f2a4f923619f431b37f547c9fe261ff3a6ddcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Tue, 26 May 2026 12:04:04 +0000 Subject: [PATCH] update main.py --- main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 23a3222..da9d4db 100644 --- a/main.py +++ b/main.py @@ -46,13 +46,14 @@ def create_virtual_file(path: str, content: str) -> str: def write_to_real_fs() -> str: """Copy all files from virtual FS to the real workspace.""" try: - for root, dirs, files in os.walk("./workspace"): - for file in files: - src = os.path.join(root, file) - dst = os.path.join("./real_files", file) + # FilesystemBackend stores files in memory; we iterate over its internal dict if available + if hasattr(backend, "_backend") and isinstance(backend._backend, FilesystemBackend): + fs = backend._backend + for path, content in fs._files.items(): + dst = os.path.join("./real_files", path.lstrip("/")) os.makedirs(os.path.dirname(dst), exist_ok=True) - with open(src, "r", encoding="utf-8") as fsrc, open(dst, "w", encoding="utf-8") as fdst: - fdst.write(fsrc.read()) + with open(dst, "w", encoding="utf-8") as f: + f.write(content) return "All virtual files written to real filesystem." except Exception as e: return f"Error writing to real FS: {e}"