1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

migrate: return on error (esp. Save)

This commit is contained in:
Tamás Gulácsi 2017-10-02 13:55:48 +02:00
parent b3b5f31575
commit 8474b79cf1

View File

@ -7,8 +7,14 @@ import (
) )
func migrate(pathToOldData, pathToData string) error { func migrate(pathToOldData, pathToData string) error {
files, _ := ioutil.ReadDir(pathToOldData) files, err := ioutil.ReadDir(pathToOldData)
if len(files) == 0 {
return err
}
for _, f := range files { for _, f := range files {
if f.Mode().IsDir() {
continue
}
fmt.Printf("Migrating %s", f.Name()) fmt.Printf("Migrating %s", f.Name())
p := Open(f.Name()) p := Open(f.Name())
bData, err := ioutil.ReadFile(path.Join(pathToOldData, f.Name())) bData, err := ioutil.ReadFile(path.Join(pathToOldData, f.Name()))
@ -19,7 +25,9 @@ func migrate(pathToOldData, pathToData string) error {
if err != nil { if err != nil {
return err return err
} }
p.Save() if err = p.Save(); err != nil {
return err
}
} }
return nil return nil
} }