mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
fix: ensure original write method is correctly restored after code execution
GitOrigin-RevId: 0c1d40bbde58d04de362586103a50b522dc14c2a
This commit is contained in:
committed by
Copybot
parent
7d032e73d6
commit
cb0f87282b
@@ -127,13 +127,13 @@ async function handleRunCode(msg: RunCodeRequest) {
|
||||
},
|
||||
})
|
||||
|
||||
const fs = instance.FS
|
||||
const originalWrite = fs.write as PyodideFS['write']
|
||||
try {
|
||||
const fs = instance.FS
|
||||
if (msg.files.length > 0) {
|
||||
syncProjectFiles(fs, msg.files)
|
||||
}
|
||||
|
||||
const originalWrite = fs.write as PyodideFS['write']
|
||||
fs.write = ((...args: Parameters<PyodideFS['write']>) => {
|
||||
const [stream] = args
|
||||
// Only surface writes to the synced project workspace, not Pyodide internals.
|
||||
@@ -144,7 +144,7 @@ async function handleRunCode(msg: RunCodeRequest) {
|
||||
writtenPaths.add(stream.path)
|
||||
}
|
||||
|
||||
return originalWrite(...args)
|
||||
return originalWrite.call(fs, ...args)
|
||||
}) as PyodideFS['write']
|
||||
|
||||
const result = await instance.runPythonAsync(msg.code)
|
||||
@@ -167,6 +167,7 @@ async function handleRunCode(msg: RunCodeRequest) {
|
||||
requestId: msg.id,
|
||||
})
|
||||
} finally {
|
||||
fs.write = originalWrite
|
||||
const outputs = [...writtenPaths].sort()
|
||||
self.postMessage({
|
||||
type: 'run-code-result',
|
||||
|
||||
Reference in New Issue
Block a user