fix: readdir

also, fix warnings on persist var
This commit is contained in:
Tienson Qin
2022-09-13 13:19:14 +08:00
committed by Andelf
parent 8915818c3f
commit c074465b8a
5 changed files with 61 additions and 52 deletions

View File

@@ -38,12 +38,14 @@
(defn read-graphs-txid-info
[root]
(when (string? root)
(-> (p/let [txid-str (fs/read-file root "logseq/graphs-txid.edn")
txid-meta (and txid-str (reader/read-string txid-str))]
txid-meta)
(p/catch
(fn [^js e]
(js/console.error "[fs read txid data error]" e))))))
(p/let [exists? (fs/file-exists? root "logseq/graphs-txid.edn")]
(when exists?
(-> (p/let [txid-str (fs/read-file root "logseq/graphs-txid.edn")
txid-meta (and txid-str (reader/read-string txid-str))]
txid-meta)
(p/catch
(fn [^js e]
(js/console.error "[fs read txid data error]" e))))))))
(defn inflate-graphs-info
[graphs]

View File

@@ -32,24 +32,26 @@
(let [repo (state/get-current-repo)
dir (config/get-repo-dir repo)
path (load-path location)]
(-> (p/chain (fs/stat dir path)
(fn [stat]
(when stat
(fs/read-file dir path)))
(fn [content]
(when (not-empty content)
(try (cljs.reader/read-string content)
(catch js/Error e
(println (util/format "read persist-var failed: %s" (load-path location)))
(js/console.dir e)))))
(fn [value]
(when (some? value)
(swap! *value (fn [o]
(-> o
(assoc-in [repo :loaded?] true)
(assoc-in [repo :value] value)))))))
(p/catch (fn [e]
(println (util/format "load persist-var failed: %s: %s" (load-path location) e))))))))
(p/let [file-exists? (fs/file-exists? dir path)]
(when file-exists?
(-> (p/chain (fs/stat dir path)
(fn [stat]
(when stat
(fs/read-file dir path)))
(fn [content]
(when (not-empty content)
(try (cljs.reader/read-string content)
(catch js/Error e
(println (util/format "read persist-var failed: %s" (load-path location)))
(js/console.dir e)))))
(fn [value]
(when (some? value)
(swap! *value (fn [o]
(-> o
(assoc-in [repo :loaded?] true)
(assoc-in [repo :value] value)))))))
(p/catch (fn [e]
(println (util/format "load persist-var failed: %s: %s" (load-path location) e))))))))))
(-loaded? [_]
(get-in @*value [(state/get-current-repo) :loaded?]))