This repository has been archived on 2025-06-10. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
server/admin/sync/importer_localfs.go
nemunaire dddf72267d admin: Implement sychronization backends
We are now able, depending on configuration, to retrieve files from either WebDAV or local file system.
2017-12-12 07:14:12 +01:00

49 lines
986 B
Go

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
}
}