Restore files
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
04e744b8e5
commit
60af2e82af
|
@ -96,7 +96,7 @@ func Create(f io.ReadCloser, realname string, realsize uint64, a web.Auth) (file
|
|||
}
|
||||
|
||||
// Save the file to storage with its new ID as path
|
||||
err = afs.WriteReader(file.getFileName(), f)
|
||||
err = file.Save(f)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -113,3 +113,8 @@ func (f *File) Delete() (err error) {
|
|||
err = afs.Remove(f.getFileName())
|
||||
return
|
||||
}
|
||||
|
||||
// Save saves a file to storage
|
||||
func (f *File) Save(fcontent io.ReadCloser) error {
|
||||
return afs.WriteReader(f.getFileName(), fcontent)
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import (
|
|||
"os"
|
||||
"sort"
|
||||
"src.techknowlogick.com/xormigrate"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -140,6 +141,31 @@ func Restore(filename string) error {
|
|||
|
||||
///////
|
||||
// Restore Files
|
||||
for i, file := range filesFiles {
|
||||
id, err := strconv.ParseInt(i, 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not parse file id %s: %s", i, err)
|
||||
}
|
||||
|
||||
f := &files.File{ID: id}
|
||||
|
||||
fc, err := file.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open file %s: %s", i, err)
|
||||
}
|
||||
|
||||
if err := f.Save(fc); err != nil {
|
||||
return fmt.Errorf("could not save file: %s", err)
|
||||
}
|
||||
|
||||
_ = fc.Close()
|
||||
log.Infof("Restored file %s", i)
|
||||
}
|
||||
log.Infof("Restored %d files.", len(filesFiles))
|
||||
|
||||
///////
|
||||
// Done
|
||||
log.Infof("Done restoring dump.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue