Fix: 修复Python Online板卡下「本地文件系统」连续多次读取目录时报错
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as path from 'path';
|
||||
import { FileTree } from 'mixly';
|
||||
import { FileTree, Debug } from 'mixly';
|
||||
import FileSystemFS from './filesystem-fs';
|
||||
|
||||
|
||||
@@ -9,36 +9,36 @@ export default class FileSystemFileTree extends FileTree {
|
||||
}
|
||||
|
||||
async readFolder(inPath) {
|
||||
const fs = this.getFS();
|
||||
const [, status] = await fs.isDirectory(inPath);
|
||||
let output = [];
|
||||
if (!status) {
|
||||
return output;
|
||||
}
|
||||
const result = await fs.readDirectory(inPath);
|
||||
let children = [];
|
||||
if (result.length == 2) {
|
||||
children = result[1];
|
||||
}
|
||||
for (let data of children) {
|
||||
const dataPath = path.join(inPath, data);
|
||||
const [, isDirectory] = await fs.isDirectory(dataPath);
|
||||
if (isDirectory) {
|
||||
const [, isDirEmpty] = await fs.isDirectoryEmpty(dataPath);
|
||||
output.push({
|
||||
type: 'folder',
|
||||
id: dataPath,
|
||||
children: !isDirEmpty,
|
||||
title: `/${this.getRootFolderName()}${dataPath}`
|
||||
});
|
||||
} else {
|
||||
output.push({
|
||||
type: 'file',
|
||||
id: dataPath,
|
||||
children: false,
|
||||
title: `/${this.getRootFolderName()}${dataPath}`
|
||||
});
|
||||
try {
|
||||
const fs = this.getFS();
|
||||
const status = await fs.isDirectory(inPath);
|
||||
if (!status) {
|
||||
return output;
|
||||
}
|
||||
const children = await fs.readDirectory(inPath);
|
||||
for (let data of children) {
|
||||
const dataPath = path.join(inPath, data);
|
||||
const isDirectory = await fs.isDirectory(dataPath);
|
||||
if (isDirectory) {
|
||||
const isDirEmpty = await fs.isDirectoryEmpty(dataPath);
|
||||
output.push({
|
||||
type: 'folder',
|
||||
id: dataPath,
|
||||
children: !isDirEmpty,
|
||||
title: `/${this.getRootFolderName()}${dataPath}`
|
||||
});
|
||||
} else {
|
||||
output.push({
|
||||
type: 'file',
|
||||
id: dataPath,
|
||||
children: false,
|
||||
title: `/${this.getRootFolderName()}${dataPath}`
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
Debug.error(error);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user