enhance: remove graph command behaves like electron remove

Moves removed graph to 'Unlinked graphs'
This commit is contained in:
Gabriel Horner
2026-03-10 11:21:00 -04:00
committed by rcmerci
parent 13d8f0e419
commit 018281da38
3 changed files with 10 additions and 12 deletions

View File

@@ -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)))
(fs/writeFileSync db-path data)))

View File

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

View File

@@ -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"))))
"Graph contents should be preserved after move"))))