Просмотр исходного кода

feat: allow deleting directories

Alex4386 1 год назад
Родитель
Сommit
4b6edc8a66
2 измененных файлов с 13 добавлено и 6 удалено
  1. 1 1
      README.md
  2. 12 5
      src/scenes/mtp/mtp.c

+ 1 - 1
README.md

@@ -29,7 +29,7 @@ If your computer can handle Android devices, it should be able to handle Flipper
   - Large file transfer now **WORKS**!
     - It didn't work since the header did not have proper `size` defined, ignoring the further packets.
     - Now utilizing even less memory via `streaming` support!
-* Deleting Files
+* Deleting Files/Directories
 
 ### Known Issues
 * Creating directories, files, uploading files are not supported yet.

+ 12 - 5
src/scenes/mtp/mtp.c

@@ -1113,12 +1113,19 @@ bool DeleteObject(AppMTP* mtp, uint32_t handle) {
         return false;
     }
 
-    if(!storage_file_exists(mtp->storage, path)) {
-        return false;
-    }
+    FileInfo fileinfo;
+    FS_Error err = storage_common_stat(mtp->storage, path, &fileinfo);
 
-    if(storage_common_remove(mtp->storage, path) != FSE_OK) {
-        return false;
+    if(err != FSE_OK) {
+        if(file_info_is_dir(&fileinfo)) {
+            if(storage_dir_remove(mtp->storage, path) != FSE_OK) {
+                return false;
+            }
+        } else {
+            if(storage_common_remove(mtp->storage, path) != FSE_OK) {
+                return false;
+            }
+        }
     }
 
     return true;