diff --git a/src/electron/electron/db.cljs b/src/electron/electron/db.cljs index e457ccbbe4..03fbe76139 100644 --- a/src/electron/electron/db.cljs +++ b/src/electron/electron/db.cljs @@ -4,6 +4,7 @@ ["path" :as node-path] [electron.backup-file :as backup-file] [logseq.cli.common.graph :as cli-common-graph] + [logseq.common.graph-dir :as graph-dir] [logseq.db.common.sqlite :as common-sqlite])) (defn ensure-graphs-dir! diff --git a/src/main/logseq/cli/common.cljs b/src/main/logseq/cli/common.cljs index a1809fc337..a7cd739ad8 100644 --- a/src/main/logseq/cli/common.cljs +++ b/src/main/logseq/cli/common.cljs @@ -4,20 +4,20 @@ ["path" :as node-path] [logseq.common.config :as common-config] [logseq.common.graph :as common-graph] - [logseq.db.common.sqlite :as common-sqlite])) + [logseq.common.graph-dir :as graph-dir])) (defn unlink-graph! "Unlinks the given repo by moving it to the 'Unlinked graphs' dir. Returns path of unlinked dir if move is successful or nil if not" [repo] - (let [db-name (common-sqlite/sanitize-db-name repo) + (let [graph-dir-name (graph-dir/repo->encoded-graph-dir-name repo) graphs-dir (common-graph/expand-home (common-graph/get-default-graphs-dir)) - path (node-path/join graphs-dir db-name) + path (node-path/join graphs-dir graph-dir-name) unlinked (node-path/join graphs-dir common-config/unlinked-graphs-dir) - new-path (node-path/join unlinked db-name) + new-path (node-path/join unlinked graph-dir-name) new-path-exists? (fs/existsSync new-path) new-path' (if new-path-exists? - (node-path/join unlinked (str db-name "-" (random-uuid))) + (node-path/join unlinked (str graph-dir-name "-" (random-uuid))) new-path)] (when (fs/existsSync path) (fs/ensureDirSync unlinked) diff --git a/src/test/logseq/cli/common_test.cljs b/src/test/logseq/cli/common_test.cljs index 39f7db4ce1..19adac802e 100644 --- a/src/test/logseq/cli/common_test.cljs +++ b/src/test/logseq/cli/common_test.cljs @@ -9,10 +9,11 @@ (deftest unlink-graph-moves-to-unlinked-dir (let [graphs-dir (node-helper/create-tmp-dir "unlink-graph") - graph-name "test-graph" + graph-name "foo/bar" repo (str common-config/db-version-prefix graph-name) - graph-path (node-path/join graphs-dir graph-name) - unlinked-path (node-path/join graphs-dir common-config/unlinked-graphs-dir graph-name)] + encoded-graph-dir "foo~2Fbar" + graph-path (node-path/join graphs-dir encoded-graph-dir) + unlinked-path (node-path/join graphs-dir common-config/unlinked-graphs-dir encoded-graph-dir)] (fs/mkdirSync graph-path #js {:recursive true}) (fs/writeFileSync (node-path/join graph-path "db.sqlite") "test-data") (with-redefs [common-graph/get-default-graphs-dir (fn [] graphs-dir)]