admin: localimporter can make symlink instead of copying whole files
This commit is contained in:
parent
d81f068eba
commit
8ed23ddc7a
5 changed files with 63 additions and 24 deletions
|
|
@ -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
|
||||
|
|
|
|||
Reference in a new issue