fix: each graph has its own directory

pull/10016/head
Tienson Qin 2023-06-26 14:13:48 +08:00
parent f811a5e18c
commit b0a5a9d3fc
3 changed files with 19 additions and 8 deletions

View File

@ -38,6 +38,16 @@
(map fix-win-path!)
(vec)))
(defn read-directories
"Given a dir, returns all the sub-directories"
[root-dir]
(let [files (fs/readdirSync root-dir #js {:withFileTypes true})]
(->> files
(remove #(.isSymbolicLink ^js %))
(remove #(string/starts-with? (.-name ^js %) "."))
(filter #(.isDirectory %))
(map #(.-name %)))))
(defn ignored-path?
"Given a graph directory and path, returns truthy value on whether the path is
ignored. Useful for contexts like reading a graph's directory and file watcher
@ -71,4 +81,4 @@
[graph-dir]
(->> (readdir graph-dir)
(remove (partial ignored-path? graph-dir))
(filter #(contains? allowed-formats (get-ext %)))))
(filter #(contains? allowed-formats (get-ext %)))))

View File

@ -22,6 +22,7 @@
(defn sanitize-db-name
[db-name]
(-> db-name
(string/replace "logseq_db_" "")
(string/replace "/" "_")
(string/replace "\\" "_")
(string/replace ":" "_"))) ;; windows
@ -71,9 +72,11 @@
(defn get-db-full-path
[db-name]
(let [db-name (sanitize-db-name db-name)
dir (get-graphs-dir)]
[db-name (node-path/join dir db-name)]))
(let [db-name' (sanitize-db-name db-name)
dir (get-graphs-dir)
graph-dir (node-path/join dir db-name')]
(fs/ensureDirSync graph-dir)
[db-name' (node-path/join graph-dir "db.sqlite")]))
(defn open-db!
[db-name]

View File

@ -227,12 +227,10 @@
(map graph-name->path))))
(defn- get-db-based-graphs
"Returns all graph names in the cache directory (starting with `logseq_db_`)"
"Returns all graph names in the cache directory"
[]
(let [dir (get-db-based-graphs-dir)]
(->> (common-graph/readdir dir)
(remove #{dir})
(map node-path/basename)
(->> (common-graph/read-directories dir)
(map graph-name->path))))
(defn- get-graphs