Skip to content

Commit 2cfee0e

Browse files
Merge pull request #97 from pyscript/micropython-path
Fix MicroPython untar/unzip paths
2 parents d49e2ef + e622027 commit 2cfee0e

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

docs/index.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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') =>
@@ -51,12 +61,12 @@ export default {
5161
const zipReader = new ZipReader(zipFileReader);
5262
for (const entry of await zipReader.getEntries()) {
5363
const { directory, filename } = entry;
54-
if (directory) {
55-
FS.mkdir(extractDir + filename);
56-
}
64+
const name = extractDir + filename;
65+
if (directory) mkdir(FS, name);
5766
else {
67+
mkdir(FS, PATH.dirname(name));
5868
const buffer = await entry.getData(new Uint8ArrayWriter);
59-
FS.writeFile(extractDir + filename, buffer, {
69+
FS.writeFile(name, buffer, {
6070
canOwn: true,
6171
});
6272
}
@@ -71,11 +81,14 @@ export default {
7181
import os, gzip, tarfile
7282
tar = tarfile.TarFile(fileobj=gzip.GzipFile(fileobj=open("${TMP}", "rb")))
7383
for f in tar:
74-
name = f"${extractDir}{f.name[2:]}"
84+
name = f"${extractDir}{f.name}"
7585
if f.type == tarfile.DIRTYPE:
7686
if f.name != "./":
7787
os.mkdir(name.strip("/"))
7888
else:
89+
dir = os.path.dirname(name)
90+
if not os.path.exists(dir):
91+
os.mkdir(dir)
7992
source = tar.extractfile(f)
8093
with open(name, "wb") as dest:
8194
dest.write(source.read())

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@
9090
"to-json-callback": "^0.1.1"
9191
},
9292
"worker": {
93-
"blob": "sha256-8x1Yej68/ZpJysyfYgjrdqQ+hQmhGh7Pol8qLUUi/g4="
93+
"blob": "sha256-/XJgFQzOwA20QOjpWtQIV+yid7Zhcbl+orgl+A/ggd8="
9494
}
9595
}

0 commit comments

Comments
 (0)