aboutsummaryrefslogtreecommitdiff
path: root/command.go
diff options
context:
space:
mode:
authorGuangxiong Lin <[email protected]>2023-01-20 23:05:54 +0800
committerGuangxiong Lin <[email protected]>2023-01-20 23:24:56 +0800
commit3f6aeea8c795b8bff59c1a8b45700d7bc44da4b9 (patch)
tree63dbe7f72fd397a55023a014b9a4eff8ded45400 /command.go
downloadzk-3f6aeea8c795b8bff59c1a8b45700d7bc44da4b9.tar.gz
zk-3f6aeea8c795b8bff59c1a8b45700d7bc44da4b9.tar.bz2
zk-3f6aeea8c795b8bff59c1a8b45700d7bc44da4b9.zip
First commit
Diffstat (limited to 'command.go')
-rw-r--r--command.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/command.go b/command.go
new file mode 100644
index 0000000..803970b
--- /dev/null
+++ b/command.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "os"
+ "path/filepath"
+)
+
+func Rename(source, target string) {
+ source, err := filepath.Abs(source)
+ if err != nil {
+ panic("Unable to get abspath of " + source)
+ }
+
+ target, err = filepath.Abs(target)
+ if err != nil {
+ panic("Unable to get abspath of " + target)
+ }
+
+ if !DocCollection.Contain(source) {
+ panic("Database doesn't contain " + source)
+ }
+
+ if err := os.Rename(source, target); err != nil {
+ panic(err)
+ }
+
+ doc := DocCollection[source]
+ for backlink := range doc.backlinks {
+ DocCollection[backlink].UpdateLinks(source, target)
+ }
+
+}