Skip to content

Commit 3493be7

Browse files
committed
Fix recursive delete, add upload labels and progress
1 parent b6e2423 commit 3493be7

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

supervisor/shared/web_workflow/static/directory.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ <h1><a href="/"><img src="/favicon.ico"/></a>&nbsp;<span id="path"></span></h1>
1616
<tbody></tbody>
1717
</table>
1818
<hr>
19-
<input type="file" id="files" multiple>
20-
<input type="file" id="dirs" multiple webkitdirectory>
19+
<label>📄 <input type="file" id="files" multiple></label>
20+
<label for="dirs">📁 <input type="file" id="dirs" multiple webkitdirectory></label>
2121
<button type="submit" id="upload">Upload</button>
22+
<label>Upload progress:<progress value="0"></progress></label>
2223
<hr>
2324
+📁&nbsp;<input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
2425
</body></html>

supervisor/shared/web_workflow/static/directory.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ async function mkdir(e) {
149149
}
150150

151151
async function upload(e) {
152+
let progress = document.querySelector("progress");
152153
let made_dirs = new Set();
154+
progress.max = files.files.length + dirs.files.length;
155+
progress.value = 0;
153156
for (const file of [...files.files, ...dirs.files]) {
154157
let file_name = file.name;
155158
if (file.webkitRelativePath) {
@@ -177,9 +180,11 @@ async function upload(e) {
177180
if (response.ok) {
178181
refresh_list();
179182
}
183+
progress.value += 1;
180184
}
181185
files.value = "";
182186
dirs.value = "";
187+
progress.value = 0;
183188
upload_button.disabled = true;
184189
}
185190

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,14 +766,21 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request *
766766
// Copied from ble file_transfer.c. We should share it.
767767
STATIC FRESULT _delete_directory_contents(FATFS *fs, const TCHAR *path) {
768768
FF_DIR dir;
769-
FRESULT res = f_opendir(fs, &dir, path);
770769
FILINFO file_info;
771770
// Check the stack since we're putting paths on it.
772771
if (mp_stack_usage() >= MP_STATE_THREAD(stack_limit)) {
773772
return FR_INT_ERR;
774773
}
774+
FRESULT res = FR_OK;
775775
while (res == FR_OK) {
776+
res = f_opendir(fs, &dir, path);
777+
if (res != FR_OK) {
778+
break;
779+
}
776780
res = f_readdir(&dir, &file_info);
781+
// We close and reopen the directory every time since we're deleting
782+
// entries and it may invalidate the directory handle.
783+
f_closedir(&dir);
777784
if (res != FR_OK || file_info.fname[0] == '\0') {
778785
break;
779786
}

0 commit comments

Comments
 (0)