2019-01-05 22:44:33 +00:00
|
|
|
package importer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/asdine/storm"
|
2020-05-31 23:12:36 +00:00
|
|
|
|
2019-01-05 22:44:33 +00:00
|
|
|
"github.com/filebrowser/filebrowser/v2/storage/bolt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Import imports an old configuration to a newer database.
|
2020-05-31 23:12:36 +00:00
|
|
|
func Import(oldDBPath, oldConf, newDBPath string) error {
|
|
|
|
oldDB, err := storm.Open(oldDBPath)
|
2019-01-05 22:44:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-31 23:12:36 +00:00
|
|
|
defer oldDB.Close()
|
2019-01-05 22:44:33 +00:00
|
|
|
|
2020-05-31 23:12:36 +00:00
|
|
|
newDB, err := storm.Open(newDBPath)
|
2019-01-05 22:44:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-31 23:12:36 +00:00
|
|
|
defer newDB.Close()
|
2019-01-05 22:44:33 +00:00
|
|
|
|
2020-05-31 23:12:36 +00:00
|
|
|
sto, err := bolt.NewStorage(newDB)
|
2019-01-09 21:37:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-01-05 22:44:33 +00:00
|
|
|
|
2020-05-31 23:12:36 +00:00
|
|
|
err = importUsers(oldDB, sto)
|
2019-01-05 22:44:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-31 23:12:36 +00:00
|
|
|
err = importConf(oldDB, oldConf, sto)
|
2019-01-05 22:44:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|