From 7238c4205ae5b9794a502b441470e800f09998e6 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 11 Nov 2021 18:31:21 +0800 Subject: [PATCH] fix: empty path when importing roam's json --- src/main/frontend/handler/external.cljs | 3 +- src/main/frontend/handler/file.cljs | 43 +++++++++++++------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/frontend/handler/external.cljs b/src/main/frontend/handler/external.cljs index cf896c850..825be898a 100644 --- a/src/main/frontend/handler/external.cljs +++ b/src/main/frontend/handler/external.cljs @@ -40,7 +40,8 @@ files) files (remove nil? files)] (repo-handler/parse-files-and-load-to-db! repo files nil) - (let [files (map (fn [{:file/keys [path content]}] [path content]) files)] + (let [files (->> (map (fn [{:file/keys [path content]}] (when path [path content])) files) + (remove nil?))] (file-handler/alter-files repo files {:add-history? false :update-db? false :update-status? false diff --git a/src/main/frontend/handler/file.cljs b/src/main/frontend/handler/file.cljs index 3fb203782..2c473ee46 100644 --- a/src/main/frontend/handler/file.cljs +++ b/src/main/frontend/handler/file.cljs @@ -249,27 +249,28 @@ (defn alter-files-handler! [repo files {:keys [finish-handler chan]} file->content] (let [write-file-f (fn [[path content]] - (let [original-content (get file->content path)] - (-> (p/let [_ (or - (util/electron?) - (nfs/check-directory-permission! repo))] - (debug/set-ack-step! path :write-file) - (fs/write-file! repo (config/get-repo-dir repo) path content - {:old-content original-content})) - (p/catch (fn [error] - (state/pub-event! [:notification/show - {:content (str "Failed to save the file " path ". Error: " - (str error)) - :status :error - :clear? false}]) - (state/pub-event! [:instrument {:type :write-file/failed - :payload {:path path - :content-length (count content) - :error-str (str error) - :error error}}]) - (log/error :write-file/failed {:path path - :content content - :error error})))))) + (when path + (let [original-content (get file->content path)] + (-> (p/let [_ (or + (util/electron?) + (nfs/check-directory-permission! repo))] + (debug/set-ack-step! path :write-file) + (fs/write-file! repo (config/get-repo-dir repo) path content + {:old-content original-content})) + (p/catch (fn [error] + (state/pub-event! [:notification/show + {:content (str "Failed to save the file " path ". Error: " + (str error)) + :status :error + :clear? false}]) + (state/pub-event! [:instrument {:type :write-file/failed + :payload {:path path + :content-length (count content) + :error-str (str error) + :error error}}]) + (log/error :write-file/failed {:path path + :content content + :error error}))))))) finish-handler (fn [] (when finish-handler (finish-handler))