Spaces:
Running
Running
Atomic workspace writes.
Browse files- server/main.py +6 -2
server/main.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
from typing import Optional
|
2 |
import dataclasses
|
3 |
import fastapi
|
4 |
-
import
|
5 |
import pathlib
|
6 |
import pydantic
|
|
|
7 |
import traceback
|
8 |
from . import ops
|
9 |
from . import basic_ops
|
@@ -88,8 +89,11 @@ def save(req: SaveRequest):
|
|
88 |
path = DATA_PATH / req.path
|
89 |
assert path.is_relative_to(DATA_PATH)
|
90 |
j = req.ws.model_dump_json(indent=2)
|
91 |
-
with
|
92 |
f.write(j)
|
|
|
|
|
|
|
93 |
|
94 |
@app.post("/api/save")
|
95 |
def save_and_execute(req: SaveRequest):
|
|
|
1 |
from typing import Optional
|
2 |
import dataclasses
|
3 |
import fastapi
|
4 |
+
import os
|
5 |
import pathlib
|
6 |
import pydantic
|
7 |
+
import tempfile
|
8 |
import traceback
|
9 |
from . import ops
|
10 |
from . import basic_ops
|
|
|
89 |
path = DATA_PATH / req.path
|
90 |
assert path.is_relative_to(DATA_PATH)
|
91 |
j = req.ws.model_dump_json(indent=2)
|
92 |
+
with tempfile.NamedTemporaryFile('w', delete_on_close=False) as f:
|
93 |
f.write(j)
|
94 |
+
f.close()
|
95 |
+
os.replace(f.name, path)
|
96 |
+
|
97 |
|
98 |
@app.post("/api/save")
|
99 |
def save_and_execute(req: SaveRequest):
|