update main.py
This commit is contained in:
@@ -46,13 +46,14 @@ def create_virtual_file(path: str, content: str) -> str:
|
|||||||
def write_to_real_fs() -> str:
|
def write_to_real_fs() -> str:
|
||||||
"""Copy all files from virtual FS to the real workspace."""
|
"""Copy all files from virtual FS to the real workspace."""
|
||||||
try:
|
try:
|
||||||
for root, dirs, files in os.walk("./workspace"):
|
# FilesystemBackend stores files in memory; we iterate over its internal dict if available
|
||||||
for file in files:
|
if hasattr(backend, "_backend") and isinstance(backend._backend, FilesystemBackend):
|
||||||
src = os.path.join(root, file)
|
fs = backend._backend
|
||||||
dst = os.path.join("./real_files", file)
|
for path, content in fs._files.items():
|
||||||
|
dst = os.path.join("./real_files", path.lstrip("/"))
|
||||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
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:
|
with open(dst, "w", encoding="utf-8") as f:
|
||||||
fdst.write(fsrc.read())
|
f.write(content)
|
||||||
return "All virtual files written to real filesystem."
|
return "All virtual files written to real filesystem."
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Error writing to real FS: {e}"
|
return f"Error writing to real FS: {e}"
|
||||||
|
|||||||
Reference in New Issue
Block a user