From 018281da389561a2744fc40291ade5043d25d02a Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Tue, 10 Mar 2026 11:21:00 -0400 Subject: [PATCH] enhance: remove graph command behaves like electron remove Moves removed graph to 'Unlinked graphs' --- src/electron/electron/db.cljs | 3 +-- src/main/logseq/cli/common.cljs | 10 +++++----- src/test/logseq/cli/common_test.cljs | 9 ++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/electron/electron/db.cljs b/src/electron/electron/db.cljs index 5d4891e861..e457ccbbe4 100644 --- a/src/electron/electron/db.cljs +++ b/src/electron/electron/db.cljs @@ -4,7 +4,6 @@ ["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! @@ -41,4 +40,4 @@ {:backups-dir backups-path :truncate-daily? true :keep-versions 12})) - (fs/writeFileSync db-path data))) \ No newline at end of file + (fs/writeFileSync db-path data))) diff --git a/src/main/logseq/cli/common.cljs b/src/main/logseq/cli/common.cljs index a7cd739ad8..a1809fc337 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.common.graph-dir :as graph-dir])) + [logseq.db.common.sqlite :as common-sqlite])) (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 [graph-dir-name (graph-dir/repo->encoded-graph-dir-name repo) + (let [db-name (common-sqlite/sanitize-db-name repo) graphs-dir (common-graph/expand-home (common-graph/get-default-graphs-dir)) - path (node-path/join graphs-dir graph-dir-name) + path (node-path/join graphs-dir db-name) unlinked (node-path/join graphs-dir common-config/unlinked-graphs-dir) - new-path (node-path/join unlinked graph-dir-name) + new-path (node-path/join unlinked db-name) new-path-exists? (fs/existsSync new-path) new-path' (if new-path-exists? - (node-path/join unlinked (str graph-dir-name "-" (random-uuid))) + (node-path/join unlinked (str db-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 e46b143cc0..39f7db4ce1 100644 --- a/src/test/logseq/cli/common_test.cljs +++ b/src/test/logseq/cli/common_test.cljs @@ -9,11 +9,10 @@ (deftest unlink-graph-moves-to-unlinked-dir (let [graphs-dir (node-helper/create-tmp-dir "unlink-graph") - graph-name "foo/bar" + graph-name "test-graph" repo (str common-config/db-version-prefix 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)] + graph-path (node-path/join graphs-dir graph-name) + unlinked-path (node-path/join graphs-dir common-config/unlinked-graphs-dir graph-name)] (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)] @@ -23,4 +22,4 @@ (is (fs/existsSync unlinked-path) "Graph directory should be moved to Unlinked graphs") (is (fs/existsSync (node-path/join unlinked-path "db.sqlite")) - "Graph contents should be preserved after move")))) \ No newline at end of file + "Graph contents should be preserved after move"))))