(module: PyodideModule)
| 33 | * @private |
| 34 | */ |
| 35 | export function initializeNativeFS(module: PyodideModule) { |
| 36 | const FS = module.FS; |
| 37 | const MEMFS = module.FS.filesystems.MEMFS; |
| 38 | const PATH = module.PATH; |
| 39 | |
| 40 | const nativeFSAsync = { |
| 41 | // DIR_MODE: {{{ cDefine('S_IFDIR') }}} | 511 /* 0777 */, |
| 42 | // FILE_MODE: {{{ cDefine('S_IFREG') }}} | 511 /* 0777 */, |
| 43 | DIR_MODE: 16384 | 511, |
| 44 | FILE_MODE: 32768 | 511, |
| 45 | mount: function (mount: any) { |
| 46 | if (!mount.opts.fileSystemHandle) { |
| 47 | throw new Error("opts.fileSystemHandle is required"); |
| 48 | } |
| 49 | |
| 50 | // reuse all of the core MEMFS functionality |
| 51 | return MEMFS.mount.apply(null, arguments); |
| 52 | }, |
| 53 | syncfs: async (mount: any, populate: Boolean, callback: Function) => { |
| 54 | try { |
| 55 | const local = nativeFSAsync.getLocalSet(mount); |
| 56 | const remote = await nativeFSAsync.getRemoteSet(mount); |
| 57 | const src = populate ? remote : local; |
| 58 | const dst = populate ? local : remote; |
| 59 | await nativeFSAsync.reconcile(mount, src, dst); |
| 60 | callback(null); |
| 61 | } catch (e) { |
| 62 | callback(e); |
| 63 | } |
| 64 | }, |
| 65 | // Returns file set of emscripten's filesystem at the mountpoint. |
| 66 | getLocalSet: (mount: any) => { |
| 67 | let entries = Object.create(null); |
| 68 | |
| 69 | function isRealDir(p: string) { |
| 70 | return p !== "." && p !== ".."; |
| 71 | } |
| 72 | |
| 73 | function toAbsolute(root: string) { |
| 74 | return (p: string) => { |
| 75 | return PATH.join2(root, p); |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | let check = FS.readdir(mount.mountpoint) |
| 80 | .filter(isRealDir) |
| 81 | .map(toAbsolute(mount.mountpoint)); |
| 82 | |
| 83 | while (check.length) { |
| 84 | let path = check.pop()!; |
| 85 | let stat = FS.stat(path); |
| 86 | |
| 87 | if (FS.isDir(stat.mode)) { |
| 88 | check.push.apply( |
| 89 | check, |
| 90 | FS.readdir(path).filter(isRealDir).map(toAbsolute(path)), |
| 91 | ); |
| 92 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…