Explorar o código

chore: make some fs operations defensive

Yukun Guo %!s(int64=5) %!d(string=hai) anos
pai
achega
2afac7059c
Modificáronse 2 ficheiros con 9 adicións e 2 borrados
  1. 8 1
      src/main/frontend/fs.cljs
  2. 1 1
      src/main/frontend/handler/page.cljs

+ 8 - 1
src/main/frontend/fs.cljs

@@ -108,7 +108,10 @@
                                            :error error})))))
 
     :else
-    (js/window.pfs.unlink path opts)))
+    (p/let [stat (js/window.pfs.stat path)]
+      (if (.-isFile stat)
+        (js/window.pfs.unlink path opts)
+        (p/rejected "Unlinking a directory is not allowed")))))
 
 (defn rmdir
   "Remove the directory recursively."
@@ -232,6 +235,10 @@
 (defn rename
   [repo old-path new-path]
   (cond
+    ; See https://github.com/isomorphic-git/lightning-fs/issues/41
+    (= old-path new-path)
+    (p/resolved nil)
+
     (local-db? old-path)
     ;; create new file
     ;; delete old file

+ 1 - 1
src/main/frontend/handler/page.cljs

@@ -253,7 +253,7 @@
         (let [file (db/get-page-file page-name)
               file-path (:file/path file)]
           ;; delete file
-          (when file-path
+          (when-not (string/blank? file-path)
             (db/transact! [[:db.fn/retractEntity [:file/path file-path]]])
             (when-let [files-conn (db/get-files-conn repo)]
               (d/transact! files-conn [[:db.fn/retractEntity [:file/path file-path]]]))