diff --git a/deps/common/src/logseq/common/graph.cljs b/deps/common/src/logseq/common/graph.cljs index abf64dfdd..8ef544bf1 100644 --- a/deps/common/src/logseq/common/graph.cljs +++ b/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 %))))) \ No newline at end of file + (filter #(contains? allowed-formats (get-ext %))))) diff --git a/src/electron/electron/db.cljs b/src/electron/electron/db.cljs index cb8966c70..c4f0082a4 100644 --- a/src/electron/electron/db.cljs +++ b/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] diff --git a/src/electron/electron/handler.cljs b/src/electron/electron/handler.cljs index 2e1a6bcd2..3ca21e840 100644 --- a/src/electron/electron/handler.cljs +++ b/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