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

34 lines
594 B
Go
Raw Permalink Normal View History

package main
import (
"fmt"
"io/ioutil"
"path"
)
func migrate(pathToOldData, pathToData string) error {
2017-10-02 14:55:48 +03:00
files, err := ioutil.ReadDir(pathToOldData)
if len(files) == 0 {
return err
}
for _, f := range files {
2017-10-02 14:55:48 +03:00
if f.Mode().IsDir() {
continue
}
fmt.Printf("Migrating %s", f.Name())
p := Open(f.Name())
bData, err := ioutil.ReadFile(path.Join(pathToOldData, f.Name()))
if err != nil {
return err
}
err = p.Update(string(bData))
if err != nil {
return err
}
2017-10-02 14:55:48 +03:00
if err = p.Save(); err != nil {
return err
}
}
return nil
}