lib/versioner: Reduce surface area (#6186)
* lib/versioner: Reduce surface area This is a refactor while I was anyway rooting around in the versioner. Instead of exporting every possible implementation and the factory and letting the caller do whatever, this now encapsulates all that and exposes a New() that takes a config.VersioningConfiguration. Given that and that we don't know (from the outside) how a versioner works or what state it keeps, we now just construct it once per folder and keep it around. Previously it was recreated for each restore request. * unparam * wip
This commit is contained in:
committed by
Audrius Butkevicius
parent
f747ba6d69
commit
4e151d380c
@@ -21,22 +21,22 @@ import (
|
||||
|
||||
func init() {
|
||||
// Register the constructor for this type of versioner with the name "external"
|
||||
Factories["external"] = NewExternal
|
||||
factories["external"] = newExternal
|
||||
}
|
||||
|
||||
type External struct {
|
||||
type external struct {
|
||||
command string
|
||||
filesystem fs.Filesystem
|
||||
}
|
||||
|
||||
func NewExternal(folderID string, filesystem fs.Filesystem, params map[string]string) Versioner {
|
||||
func newExternal(filesystem fs.Filesystem, params map[string]string) Versioner {
|
||||
command := params["command"]
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
command = strings.Replace(command, `\`, `\\`, -1)
|
||||
}
|
||||
|
||||
s := External{
|
||||
s := external{
|
||||
command: command,
|
||||
filesystem: filesystem,
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func NewExternal(folderID string, filesystem fs.Filesystem, params map[string]st
|
||||
|
||||
// Archive moves the named file away to a version archive. If this function
|
||||
// returns nil, the named file does not exist any more (has been archived).
|
||||
func (v External) Archive(filePath string) error {
|
||||
func (v external) Archive(filePath string) error {
|
||||
info, err := v.filesystem.Lstat(filePath)
|
||||
if fs.IsNotExist(err) {
|
||||
l.Debugln("not archiving nonexistent file", filePath)
|
||||
@@ -107,10 +107,10 @@ func (v External) Archive(filePath string) error {
|
||||
return errors.New("Versioner: file was not removed by external script")
|
||||
}
|
||||
|
||||
func (v External) GetVersions() (map[string][]FileVersion, error) {
|
||||
func (v external) GetVersions() (map[string][]FileVersion, error) {
|
||||
return nil, ErrRestorationNotSupported
|
||||
}
|
||||
|
||||
func (v External) Restore(filePath string, versionTime time.Time) error {
|
||||
func (v external) Restore(filePath string, versionTime time.Time) error {
|
||||
return ErrRestorationNotSupported
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user