Переглянути джерело

review fixes

tags/v0.12.0
Shivaram Lingamneni 6 роки тому
джерело
коміт
3db71415c9
4 змінених файлів з 38 додано та 33 видалено
  1. 1
    1
      irc/config.go
  2. 3
    30
      irc/database.go
  3. 31
    0
      irc/utils/os.go
  4. 3
    2
      oragono.yaml

+ 1
- 1
irc/config.go Переглянути файл

@@ -230,7 +230,7 @@ type Config struct {
230 230
 
231 231
 	Datastore struct {
232 232
 		Path        string
233
-		AutoUpgrade *bool
233
+		AutoUpgrade bool
234 234
 	}
235 235
 
236 236
 	Accounts AccountConfig

+ 3
- 30
irc/database.go Переглянути файл

@@ -8,7 +8,6 @@ import (
8 8
 	"encoding/base64"
9 9
 	"encoding/json"
10 10
 	"fmt"
11
-	"io"
12 11
 	"log"
13 12
 	"os"
14 13
 	"strings"
@@ -16,6 +15,7 @@ import (
16 15
 
17 16
 	"github.com/oragono/oragono/irc/modes"
18 17
 	"github.com/oragono/oragono/irc/passwd"
18
+	"github.com/oragono/oragono/irc/utils"
19 19
 
20 20
 	"github.com/tidwall/buntdb"
21 21
 )
@@ -88,11 +88,7 @@ func InitDB(path string) {
88 88
 
89 89
 // OpenDatabase returns an existing database, performing a schema version check.
90 90
 func OpenDatabase(config *Config) (*buntdb.DB, error) {
91
-	allowAutoupgrade := true
92
-	if config.Datastore.AutoUpgrade != nil {
93
-		allowAutoupgrade = *config.Datastore.AutoUpgrade
94
-	}
95
-	return openDatabaseInternal(config, allowAutoupgrade)
91
+	return openDatabaseInternal(config, config.Datastore.AutoUpgrade)
96 92
 }
97 93
 
98 94
 // open the database, giving it at most one chance to auto-upgrade the schema
@@ -140,36 +136,13 @@ func openDatabaseInternal(config *Config, allowAutoupgrade bool) (db *buntdb.DB,
140 136
 	}
141 137
 }
142 138
 
143
-// implementation of `cp` (go should really provide this...)
144
-func cpFile(src string, dst string) (err error) {
145
-	in, err := os.Open(src)
146
-	if err != nil {
147
-		return
148
-	}
149
-	defer in.Close()
150
-	out, err := os.Create(dst)
151
-	if err != nil {
152
-		return
153
-	}
154
-	defer func() {
155
-		closeError := out.Close()
156
-		if err == nil {
157
-			err = closeError
158
-		}
159
-	}()
160
-	if _, err = io.Copy(out, in); err != nil {
161
-		return
162
-	}
163
-	return
164
-}
165
-
166 139
 func performAutoUpgrade(currentVersion string, config *Config) (err error) {
167 140
 	path := config.Datastore.Path
168 141
 	log.Printf("attempting to auto-upgrade schema from version %s to %s\n", currentVersion, latestDbSchema)
169 142
 	timestamp := time.Now().UTC().Format("2006-01-02-15:04:05.000Z")
170 143
 	backupPath := fmt.Sprintf("%s.v%s.%s.bak", path, currentVersion, timestamp)
171 144
 	log.Printf("making a backup of current database at %s\n", backupPath)
172
-	err = cpFile(path, backupPath)
145
+	err = utils.CopyFile(path, backupPath)
173 146
 	if err != nil {
174 147
 		return err
175 148
 	}

+ 31
- 0
irc/utils/os.go Переглянути файл

@@ -0,0 +1,31 @@
1
+// Copyright (c) 2018 Shivaram Lingamneni
2
+
3
+package utils
4
+
5
+import (
6
+	"io"
7
+	"os"
8
+)
9
+
10
+// implementation of `cp` (go should really provide this...)
11
+func CopyFile(src string, dst string) (err error) {
12
+	in, err := os.Open(src)
13
+	if err != nil {
14
+		return
15
+	}
16
+	defer in.Close()
17
+	out, err := os.Create(dst)
18
+	if err != nil {
19
+		return
20
+	}
21
+	defer func() {
22
+		closeError := out.Close()
23
+		if err == nil {
24
+			err = closeError
25
+		}
26
+	}()
27
+	if _, err = io.Copy(out, in); err != nil {
28
+		return
29
+	}
30
+	return
31
+}

+ 3
- 2
oragono.yaml Переглянути файл

@@ -341,8 +341,9 @@ debug:
341 341
 datastore:
342 342
     # path to the datastore
343 343
     path: ircd.db
344
-    # if the database schema requires an upgrade, `autoupgrade` (which defaults to true)
345
-    # will attempt to perform it automatically on startup. the database will be backed
344
+
345
+    # if the database schema requires an upgrade, `autoupgrade` will attempt to
346
+    # perform it automatically on startup. the database will be backed
346 347
     # up, and if the upgrade fails, the original database will be restored.
347 348
     autoupgrade: true
348 349
 

Завантаження…
Відмінити
Зберегти