Skip to content

Commit 9d5e63c

Browse files
committed
Fix MicroPython untar/unzip paths
1 parent a47febd commit 9d5e63c

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

esm/interpreter/micropython.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ const type = 'micropython';
99

1010
// REQUIRES INTEGRATION TEST
1111
/* c8 ignore start */
12+
const mkdir = (FS, path) => {
13+
try {
14+
FS.mkdir(path);
15+
}
16+
// eslint-disable-next-line no-unused-vars
17+
catch (_) {
18+
// ignore as there's no path.exists here
19+
}
20+
};
21+
1222
export default {
1323
type,
1424
module: (version = '1.22.0-272') =>
@@ -53,12 +63,12 @@ export default {
5363
const zipReader = new ZipReader(zipFileReader);
5464
for (const entry of await zipReader.getEntries()) {
5565
const { directory, filename } = entry;
56-
if (directory) {
57-
FS.mkdir(extractDir + filename);
58-
}
66+
const name = extractDir + filename;
67+
if (directory) mkdir(FS, name);
5968
else {
69+
mkdir(FS, PATH.dirname(name));
6070
const buffer = await entry.getData(new Uint8ArrayWriter);
61-
FS.writeFile(extractDir + filename, buffer, {
71+
FS.writeFile(name, buffer, {
6272
canOwn: true,
6373
});
6474
}
@@ -73,11 +83,14 @@ export default {
7383
import os, gzip, tarfile
7484
tar = tarfile.TarFile(fileobj=gzip.GzipFile(fileobj=open("${TMP}", "rb")))
7585
for f in tar:
76-
name = f"${extractDir}{f.name[2:]}"
86+
name = f"${extractDir}{f.name}"
7787
if f.type == tarfile.DIRTYPE:
7888
if f.name != "./":
7989
os.mkdir(name.strip("/"))
8090
else:
91+
dir = os.path.dirname(name)
92+
if not os.path.exists(dir):
93+
os.mkdir(dir)
8194
source = tar.extractfile(f)
8295
with open(name, "wb") as dest:
8396
dest.write(source.read())

0 commit comments

Comments
 (0)