Skip to content

Commit 62fddec

Browse files
committed
Fixed getItemStat returns null issue + reduce size of fsIsDir calls
Signed-off-by: paulober <[email protected]>
1 parent 0db0cee commit 62fddec

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/serialHelper.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,6 @@ def __pe_get_file_info(file_path):
801801
modification_time = stat[8]
802802
size = stat[6]
803803
print('{"creationTime": ' + str(creation_time) + ', "modificationTime": ' + str(modification_time) + ', "size": ' + str(size) + ', "isDir": ' + str((stat[0] & 0o170000) == 0o040000).lower() + '}')
804-
del _pe_os
805804
`;
806805

807806
try {
@@ -810,7 +809,7 @@ del _pe_os
810809
command +
811810
`__pe_get_file_info('${item}')\n` +
812811
// cleanup memory
813-
"del __pe_get_file_info",
812+
"del __pe_get_file_info\ndel _pe_os",
814813
emitter
815814
);
816815

@@ -1294,13 +1293,10 @@ export async function fsIsDir(
12941293
): Promise<boolean> {
12951294
const command = `
12961295
import os as _pe_os
1297-
def __pe_is_dir(file_path):
1298-
try:
1299-
return (_pe_os.stat(file_path)[0] & 0o170000) == 0o040000
1300-
except OSError:
1301-
return False
1302-
print(__pe_is_dir('${target}'))
1303-
del __pe_is_dir
1296+
try:
1297+
print((_pe_os.stat('${target}')[0] & 0o170000) == 0o040000)
1298+
except OSError:
1299+
print(False)
13041300
del _pe_os
13051301
`;
13061302

@@ -1450,11 +1446,12 @@ export async function runRemoteFile(
14501446
}
14511447

14521448
try {
1449+
// del os as running the remote may require every bit of memory
14531450
await executeCommand(
14541451
port,
14551452
`import os as _pe_os; _pe_dir=_pe_os.getcwd(); _pe_os.chdir('${dirnamePosix(
14561453
file
1457-
)}'); del _pe_os;`,
1454+
)}'); del _pe_os`,
14581455
emitter,
14591456
undefined,
14601457
true,

src/tests/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { PicoMpyCom } from "../picoMpyCom.js";
22
import { createInterface } from "readline";
33
import { PicoSerialEvents } from "../picoSerialEvents.js";
44
import { OperationResultType } from "../operationResult.js";
5-
import { hardReset, runRemoteFile } from "../serialHelper.js";
65

76
const serialCom = PicoMpyCom.getInstance();
87

0 commit comments

Comments
 (0)