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}"