mirror of
https://github.com/logseq/logseq.git
synced 2026-05-28 06:34:34 +00:00
fix(fs): impl mkdir-recur! for memory-fs
This commit is contained in:
@@ -438,10 +438,7 @@
|
||||
|
||||
(defn get-repo-fpath
|
||||
[repo-url path]
|
||||
(if (and (or (util/electron?) (mobile-util/native-platform?))
|
||||
(local-db? repo-url))
|
||||
(path/path-join (get-repo-dir repo-url) path)
|
||||
(util/node-path.join (get-repo-dir repo-url) path)))
|
||||
(path/path-join (get-repo-dir repo-url) path))
|
||||
|
||||
(defn get-repo-config-path
|
||||
[]
|
||||
|
||||
@@ -46,6 +46,34 @@
|
||||
(js/window.pfs.mkdir dir)))))
|
||||
|
||||
|
||||
(defn- <exists?
|
||||
"dir is path, without memory:// prefix for simplicity"
|
||||
[dir]
|
||||
(-> (js/window.pfs.stat dir)
|
||||
(p/then (fn [stat]
|
||||
(not (nil? stat))))
|
||||
(p/catch (fn [_]
|
||||
nil))))
|
||||
|
||||
(defn- <mkdir-recur!
|
||||
"mkdir, recursively create parent directories if not exist
|
||||
|
||||
lightning-fs does not support's :recursive in mkdir options"
|
||||
[dir]
|
||||
(p/let [fpath (path/url-to-path dir)
|
||||
sub-dirs (p/loop [top-parent fpath
|
||||
remains []]
|
||||
(p/let [exists? (<exists? top-parent)]
|
||||
(if exists?
|
||||
(reverse remains) ;; top-parent is the first non-exist dir
|
||||
(p/recur (path/parent top-parent)
|
||||
(conj remains top-parent)))))]
|
||||
(p/loop [remains sub-dirs]
|
||||
(if (empty? remains)
|
||||
(p/resolved nil)
|
||||
(p/do! (js/window.pfs.mkdir (first remains))
|
||||
(p/recur (rest remains)))))))
|
||||
|
||||
(defrecord MemoryFs []
|
||||
protocol/Fs
|
||||
(mkdir! [_this dir]
|
||||
@@ -57,7 +85,7 @@
|
||||
(mkdir-recur! [_this dir]
|
||||
(when js/window.pfs
|
||||
(let [fpath (path/url-to-path dir)]
|
||||
(-> (js/window.pfs.mkdir fpath #js {:recursive true})
|
||||
(-> (<mkdir-recur! fpath)
|
||||
(p/catch (fn [error] (println "(memory-fs)Mkdir-recur error: " error)))))))
|
||||
|
||||
(readdir [_this dir]
|
||||
|
||||
Reference in New Issue
Block a user