1
0
Эх сурвалжийг харах

fix: each graph has its own directory

Tienson Qin 2 жил өмнө
parent
commit
b0a5a9d3fc

+ 11 - 1
deps/common/src/logseq/common/graph.cljs

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

+ 6 - 3
src/electron/electron/db.cljs

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

+ 2 - 4
src/electron/electron/handler.cljs

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