sync: Add Init and Sync functions
Init initializes the directory/repository before the first use. Sync is called to unsure the directory is up-to-date.
This commit is contained in:
parent
281056a723
commit
aebfb7bf96
7 changed files with 62 additions and 6 deletions
|
|
@ -2,6 +2,7 @@ package sync
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
|
@ -11,7 +12,7 @@ import (
|
|||
// inside a local directory from your filesystem.
|
||||
type LocalImporter struct {
|
||||
// Base is the root directory used by the LocalImporter. It should contains all themes.
|
||||
Base string
|
||||
Base string
|
||||
// Symlink changes the normal file copy/concatenate behaviour to symlink/concatenate.
|
||||
// If enable, your base directory must be accessible by the frontend processus as it will follow the symlink.
|
||||
Symlink bool
|
||||
|
|
@ -25,6 +26,23 @@ func (i LocalImporter) Kind() string {
|
|||
}
|
||||
}
|
||||
|
||||
func (i LocalImporter) Init() error {
|
||||
if f, err := os.Stat(i.Base); os.IsNotExist(err) {
|
||||
if err = os.Mkdir(i.Base, 0751); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
return err
|
||||
} else if !f.IsDir() {
|
||||
return fmt.Errorf("%q exists and is not a directory", i.Base)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i LocalImporter) Sync() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i LocalImporter) exists(filename string) bool {
|
||||
_, err := os.Stat(i.toURL(filename))
|
||||
return !os.IsNotExist(err)
|
||||
|
|
@ -46,7 +64,7 @@ func (i LocalImporter) importFile(URI string, next func(string, string) (interfa
|
|||
os.Symlink(i.toURL(URI), dest)
|
||||
return next(dest, URI)
|
||||
} else {
|
||||
os.Symlink(i.toURL(URI) + "_MERGED", dest)
|
||||
os.Symlink(i.toURL(URI)+"_MERGED", dest)
|
||||
return ImportFile(i, URI, next)
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Reference in a new issue