mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
37 lines
709 B
Go
Executable File
37 lines
709 B
Go
Executable File
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"path"
|
|
|
|
"github.com/jcelliott/lumber"
|
|
)
|
|
|
|
func Migrate(pathToOldData, pathToData string, logger *lumber.ConsoleLogger) error {
|
|
files, err := ioutil.ReadDir(pathToOldData)
|
|
if len(files) == 0 {
|
|
return err
|
|
}
|
|
s := Site{PathToData: pathToData, Logger: lumber.NewConsoleLogger(lumber.TRACE)}
|
|
for _, f := range files {
|
|
if f.Mode().IsDir() {
|
|
continue
|
|
}
|
|
fmt.Printf("Migrating %s", f.Name())
|
|
p := s.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
|
|
}
|
|
if err = p.Save(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|