Merge pull request #23 from tsynik/read-only-db

add read-only db work mode
This commit is contained in:
YouROK
2020-11-03 10:36:50 +03:00
committed by GitHub
4 changed files with 18 additions and 4 deletions

View File

@@ -22,9 +22,10 @@ func openDB() error {
}
var err error
db, err = bolt.Open(filepath.Join(Path, "torrserver.db"), 0666, nil)
var ro = Get().ReadOnlyMode
db, err = bolt.Open(filepath.Join(Path, "torrserver.db"), 0666, &bolt.Options{ReadOnly: ro})
if err != nil {
fmt.Print(err)
fmt.Println(err)
return err
}

View File

@@ -39,6 +39,7 @@ type Settings struct {
DisableUPNP bool
DisableDHT bool
DisableUpload bool
ReadOnlyMode bool
Encryption int // 0 - Enable, 1 - disable, 2 - force
DownloadRateLimit int // in kb, 0 - inf
UploadRateLimit int // in kb, 0 - inf
@@ -115,3 +116,10 @@ func SaveSettings() error {
return setsDB.Put([]byte("json"), []byte(buf))
})
}
func SetRDB() {
SaveSettings()
fmt.Println("Enable Read-only DB mode")
CloseDB()
sets.ReadOnlyMode = true
}