admin: localimporter can make symlink instead of copying whole files

This commit is contained in:
nemunaire 2017-12-12 07:13:38 +01:00 committed by Pierre-Olivier Mercier
commit 8ed23ddc7a
5 changed files with 63 additions and 24 deletions

View file

@ -8,15 +8,20 @@ import (
)
type LocalImporter struct {
Base string
Base string
Symlink bool
}
func (i LocalImporter) Kind() string {
return "local file importer: " + i.Base
if i.Symlink {
return "local file importer (through symlink): " + i.Base
} else {
return "local file importer: " + i.Base
}
}
func (i LocalImporter) exists(filename string) bool {
_, err := os.Stat(path.Join(i.Base, filename))
_, err := os.Stat(i.toURL(filename))
return !os.IsNotExist(err)
}
@ -24,6 +29,24 @@ func (i LocalImporter) toURL(filename string) string {
return path.Join(i.Base, filename)
}
func (i LocalImporter) importFile(URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
if i.Symlink {
dest := getDestinationFilePath(URI)
if err := os.MkdirAll(path.Dir(dest), 0755); err != nil {
return nil, err
}
if i.exists(URI) {
os.Symlink(i.toURL(URI), dest)
} else {
os.Symlink(i.toURL(URI) + "_MERGED", dest)
}
}
return ImportFile(i, URI, next)
}
func (i LocalImporter) getFile(filename string, writer *bufio.Writer) error {
if fd, err := os.Open(path.Join(i.Base, filename)); err != nil {
return err