admin: Implement sychronization backends

We are now able, depending on configuration, to retrieve files from either WebDAV or local file system.
This commit is contained in:
nemunaire 2017-11-27 02:45:33 +01:00 committed by Pierre-Olivier Mercier
commit 8f7de926d3
7 changed files with 281 additions and 160 deletions

View file

@ -0,0 +1,49 @@
package sync
import (
"bufio"
"io/ioutil"
"os"
"path"
)
type LocalImporter struct {
Base string
}
func (i LocalImporter) Kind() string {
return "local file importer: " + i.Base
}
func (i LocalImporter) exists(filename string) bool {
_, err := os.Stat(path.Join(i.Base, filename))
return !os.IsNotExist(err)
}
func (i LocalImporter) toURL(filename string) string {
return path.Join(i.Base, filename)
}
func (i LocalImporter) getFile(filename string, writer *bufio.Writer) error {
if fd, err := os.Open(path.Join(i.Base, filename)); err != nil {
return err
} else {
defer fd.Close()
reader := bufio.NewReader(fd)
reader.WriteTo(writer)
writer.Flush()
return nil
}
}
func (i LocalImporter) listDir(filename string) ([]string, error) {
if files, err := ioutil.ReadDir(path.Join(i.Base, filename)); err != nil {
return nil, err
} else {
res := make([]string, 0)
for _, file := range files {
res = append(res, file.Name())
}
return res, nil
}
}