Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions js/common/ble-file-transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ class FileTransferClient extends BLEFileTransferClient {
this._signalMutatingOp();
}
result = await operation();
} catch (error) {
// The BLE library rejects with a string for STATUS_ERROR_READONLY.
if (mutating && error === "Filesystem is read-only") {
const writeProtectedError = new Error(error);
writeProtectedError.writeProtected = true;
throw writeProtectedError;
}
throw error;
} finally {
this._fileRequestInProgress = false;
}
Expand Down Expand Up @@ -180,19 +188,9 @@ class FileTransferClient extends BLEFileTransferClient {
}

async readOnly() {
let readonly = false;
// The BLE protocol reports read-only status on a file operation.
// Keep writes available so users can save once they release the drive.
return false;
// Check if the device is read only
console.log("Checking if device is read only");
// Attempt to write a 0-byte temp file and remove it
const testPath = '/._ble_readonly_check';
try {
await this.writeFile(testPath, 0, new Uint8Array(0));
await this.deleteFile(testPath);
} catch (e) {
readonly = true;
}
return readonly;
}

async versionInfo() {
Expand Down
18 changes: 11 additions & 7 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,15 +1240,19 @@ async function saveFileContents(path, savingWorkflow, selection) {
return false;
}
offset = 0;
// If the device cleanly told us the filesystem is held by
// someone else (most commonly USB-MSC: the host has
// CIRCUITPY mounted), retrying won't help -- surface an
// actionable hint immediately and bail. Older CircuitPython
// firmware returns 500 for this case, newer firmware
// returns 409 Conflict; web-file-transfer.js tags both
// with `writeProtected` so we can treat them the same way.
// BLE and web file transfers tag explicit read-only
// responses so saves can stop without retrying.
if (e && e.writeProtected) {
setSaved(false);
if (savingWorkflow.type === CONNTYPE.Ble) {
await showMessage(
"The board's filesystem is read-only over Bluetooth. " +
"If USB storage is holding it, eject CIRCUITPY and disconnect USB data " +
"while keeping the board powered, or disable USB Mass Storage in boot.py and reset the board. " +
"Your edits are still here. Save again once the filesystem is writable."
);
return false;
}
const learnUrl = e.helpUrl || "https://learn.adafruit.com/getting-started-with-web-workflow-using-the-code-editor/device-setup#disabling-usb-mass-storage-3125964";
const learnLabel = e.helpLabel || "Disabling USB Mass Storage (Adafruit Learn)";
// MessageModal renders via innerHTML, so real markup
Expand Down