Skip to content

Commit c892e92

Browse files
Fs: Limit space available to users.
1 parent 344d599 commit c892e92

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

python-main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,10 @@ function web_editor(config) {
661661
// Sets up the file system and adds the initial main.py
662662
function setupFilesystem() {
663663
micropythonFs = new microbitFs.MicropythonFsHex($('#firmware').text());
664-
micropythonFs.write('main.py', EDITOR.getCode()); // Add main.py
664+
// Limit filesystem size to 20K
665+
micropythonFs.setStorageSize(20 * 1024);
666+
// The the current main.py
667+
micropythonFs.write('main.py', EDITOR.getCode());
665668
}
666669

667670
// Based on the Python code magic comment it detects a module

tests/spec/puppeteer-fs-spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ describe("Puppeteer filesystem tests for the Python Editor.", function() {
2323
it("Can store the correct number of small files in the filesystem", async function() {
2424
const page = await browser.newPage();
2525
await page.goto("http://localhost:5000/editor.html");
26-
// We expect to be able to add 214 small files to the fs.
27-
const expectedFileLimit = 215;
26+
// We expect to be able to add 160 small files to the fs (ignoring main.py)
27+
const expectedFileLimit = 159;
2828
let fileNameList = [];
2929
let fileCleanUps = [];
3030

3131
await page.click("#command-files");
3232
const fileInput = await page.$("#fs-file-upload-input");
33-
// Create small1.py -> small215.py (215 small files)
33+
// Create small1.py -> small159.py (160 small files)
3434
for (let i = 1; i <= expectedFileLimit; i++) {
3535
var tmpFile = tmp.fileSync({ prefix: 'small' + i + '-', postfix: '.py' });
3636
fs.writeFileSync(tmpFile.fd, `# Empty Python file < 128 bytes small${i}.py`);
@@ -69,7 +69,7 @@ describe("Puppeteer filesystem tests for the Python Editor.", function() {
6969

7070
await page.click("#command-files");
7171
const fileInput = await page.$("#file-upload-input");
72-
await fileInput.uploadFile("./spec/test-files/large.py");
72+
await fileInput.uploadFile("./spec/test-files/large-20k.py");
7373
for (let ms = 0; ms < 1000; ms += msStep) {
7474
codeContent = await page.evaluate("window.EDITOR.getCode();");
7575
if (codeContent != initialCode) break;
@@ -87,9 +87,9 @@ describe("Puppeteer filesystem tests for the Python Editor.", function() {
8787

8888
// Max filesize = ([27 * 1024] * [126 / 128])
8989
// We use a slightly smaller file (as this doesn't fully compensate for headers)
90-
expect(codeContent).toHaveLength(27204);
90+
expect(codeContent).toHaveLength(20141);
9191
expect(codeContent).toContain("import love");
92-
expect(codeName).toEqual("large");
92+
expect(codeName).toEqual("large-20k");
9393
expect(noErrorOnDownload).toEqual(true);
9494
});
9595

@@ -102,7 +102,7 @@ describe("Puppeteer filesystem tests for the Python Editor.", function() {
102102
let rejectedLargeFileLoad = false;
103103

104104
page.on("dialog", async (dialog) => {
105-
if (dialog.message().includes("Not enough space")) {
105+
if (dialog.message().includes("There is no storage space left.")) {
106106
rejectedLargeFileLoad = true;
107107
}
108108
await dialog.accept();

tests/spec/puppeteer-spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe("Puppeteer basic tests for the Python Editor.", function() {
100100
expect(codeName).toEqual("0.9");
101101
});
102102

103-
it("Shows an error when trying to download a Hex file if the Python code us too large", async function() {
103+
it("Shows an error when trying to download a Hex file if the Python code is too large", async function() {
104104
const page = await browser.newPage();
105105
await page.goto("http://localhost:5000/editor.html");
106106
const initialCode = await page.evaluate("window.EDITOR.getCode();");
@@ -128,10 +128,10 @@ describe("Puppeteer basic tests for the Python Editor.", function() {
128128
const codeName = await page.evaluate("document.getElementById('script-name').value");
129129
// TODO: WHY is this wait necessary??
130130
await page.waitFor(1000);
131-
// But when we try to downlod the hex, we get an expected error
131+
// But when we try to download the hex, we get an expected error
132132
page.removeListener("dialog", fileRejected);
133133
page.on("dialog", async (dialog) => {
134-
if (dialog.message().includes("Not enough space")) {
134+
if (dialog.message().includes("There is no storage space left.")) {
135135
rejectedLargeHexDownload = true;
136136
}
137137
await dialog.accept();

0 commit comments

Comments
 (0)