1
0
Эх сурвалжийг харах

feat(chrome-native-fs): confirm permission before write the file

Tienson Qin 5 жил өмнө
parent
commit
b9ddb875b9

+ 4 - 3
src/main/frontend/fs.cljs

@@ -275,6 +275,7 @@
 
 (defn check-directory-permission!
   [repo]
-  (p/let [handle (idb/get-item (str "handle/" repo))]
-    (when handle
-      (utils/verifyPermission handle true))))
+  (when (config/local-db? repo)
+    (p/let [handle (idb/get-item (str "handle/" repo))]
+      (when handle
+        (utils/verifyPermission handle true)))))

+ 6 - 6
src/main/frontend/handler/file.cljs

@@ -173,12 +173,12 @@
                             (db/reset-file! repo path content)
                             (db/set-file-content! repo path content))
                           (let [original-content (get file->content path)]
-                            (util/p-handle
-                             (fs/write-file (util/get-repo-dir repo) path content original-content)
-                             (fn [_])
-                             (fn [error]
-                               (println "Write file failed, path: " path ", content: " content)
-                               (js/console.error error)))))
+                            (-> (p/let [_ (fs/check-directory-permission! repo)]
+                                  (fs/write-file (util/get-repo-dir repo) path content original-content))
+                                (p/catch (fn [error]
+                                           (log/error :write-file/failed {:path path
+                                                                          :content content
+                                                                          :error error}))))))
            git-add-f (fn [_result]
                        (let [add-helper
                              (fn []