Skip to content

Commit

Permalink
Don't ignore errors when initializing the nativeFS (pyodide#5434)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and hoodmane committed Feb 24, 2025
1 parent 93bfcff commit b023f2e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/project/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ myst:
_Insert Date Here_

- Added the `context` parameter to `WebLoop.create_task()` {pr}`5431`
- {{ Fix }} `mountNativeFS` API now correctly propagates the error. {pr}`5434`

### Packages

Expand Down
6 changes: 3 additions & 3 deletions src/js/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
syncUpSnapshotLoad1,
syncUpSnapshotLoad2,
} from "./snapshot";
import { syncLocalToRemote, syncRemoteToLocal } from "./nativefs";

// Exported for micropip
API.loadBinaryFile = loadBinaryFile;
Expand Down Expand Up @@ -556,12 +557,11 @@ export class PyodideAPI {
);

// sync native ==> browser
await new Promise((resolve, _) => Module.FS.syncfs(true, resolve));
await syncRemoteToLocal(Module);

return {
// sync browser ==> native
syncfs: async () =>
new Promise((resolve, _) => Module.FS.syncfs(false, resolve)),
syncfs: async () => await syncLocalToRemote(Module),
};
}

Expand Down
29 changes: 29 additions & 0 deletions src/js/nativefs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
import { Module } from "./types";

/**
* @private
*/
async function syncfs(m: Module, direction: boolean): Promise<void> {
return new Promise((resolve, reject) => {
m.FS.syncfs(direction, (err: any) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}

/**
* @private
*/
export async function syncLocalToRemote(m: Module): Promise<void> {
return await syncfs(m, false);
}

/**
* @private
*/
export async function syncRemoteToLocal(m: Module): Promise<void> {
return await syncfs(m, true);
}

/**
* @private
*/
Expand Down

0 comments on commit b023f2e

Please sign in to comment.