Fix: 修复Python Online板卡下对本地目录操作对象的缓存没有在退出后清除
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -33,13 +33,13 @@ export default class FileSystemFS extends FS {
|
|||||||
if (permissionStatus !== 'granted') {
|
if (permissionStatus !== 'granted') {
|
||||||
throw new Error('readwrite access to directory not granted');
|
throw new Error('readwrite access to directory not granted');
|
||||||
}
|
}
|
||||||
await set('mixly-pyodide-fs', directoryHandle);
|
await this.setFSCache(directoryHandle);
|
||||||
this.#fs_ = new WebAccessFSExt(directoryHandle);
|
this.#fs_ = new WebAccessFSExt(directoryHandle);
|
||||||
return directoryHandle;
|
return directoryHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadFS() {
|
async loadFS() {
|
||||||
let directoryHandle = await get('mixly-pyodide-fs');
|
let directoryHandle = await this.getFSCache();
|
||||||
if (!directoryHandle) {
|
if (!directoryHandle) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,14 @@ export default class FileSystemFS extends FS {
|
|||||||
return directoryHandle;
|
return directoryHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getFSCache() {
|
||||||
|
return get('mixly-pyodide-fs');
|
||||||
|
}
|
||||||
|
|
||||||
|
async setFSCache(data) {
|
||||||
|
await set('mixly-pyodide-fs', data);
|
||||||
|
}
|
||||||
|
|
||||||
async createFile(filePath) {
|
async createFile(filePath) {
|
||||||
return this.#fs_.createFile(filePath, '');
|
return this.#fs_.createFile(filePath, '');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -428,13 +428,18 @@ export default class StatusBarFileSystem extends PageBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
closeFS() {
|
closeFS() {
|
||||||
const rootPath = '/' + this.#fileTree_.getRootFolderTitle();
|
const rootPath = this.#fileTree_.getRootFolderTitle();
|
||||||
|
const rootContents = Object.keys(window.pyodide.FS.root.contents);
|
||||||
|
if (rootContents.includes(path.basename(rootPath))) {
|
||||||
const lookup = window.pyodide.FS.lookupPath(rootPath, {
|
const lookup = window.pyodide.FS.lookupPath(rootPath, {
|
||||||
follow_mount: false
|
follow_mount: false
|
||||||
});
|
});
|
||||||
if (window.pyodide.FS.isMountpoint(lookup.node)) {
|
if (window.pyodide.FS.isMountpoint(lookup.node)) {
|
||||||
window.pyodide.FS.unmount(rootPath);
|
window.pyodide.FS.unmount(rootPath);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
const fs = this.#fileTree_.getFS();
|
||||||
|
fs.setFSCache(null);
|
||||||
this.#fileTree_.deselectAll();
|
this.#fileTree_.deselectAll();
|
||||||
this.hideFileTree();
|
this.hideFileTree();
|
||||||
this.hideEditor();
|
this.hideEditor();
|
||||||
|
|||||||
Reference in New Issue
Block a user