fix: empty path when importing roam's json

pull/3117/head
Tienson Qin 2021-11-11 18:31:21 +08:00
parent eaeca30e58
commit 7238c4205a
2 changed files with 24 additions and 22 deletions

View File

@ -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

View File

@ -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))