Add repoPath and repoID as parameters to versioner factory (fixes #531)

This commit is contained in:
Jakob Borg 2014-08-17 07:52:26 +02:00
parent 668b429615
commit d20df12168
3 changed files with 13 additions and 11 deletions

View File

@ -113,7 +113,7 @@ func newPuller(repoCfg config.RepositoryConfiguration, model *Model, slots int,
if !ok {
l.Fatalf("Requested versioning type %q that does not exist", repoCfg.Versioning.Type)
}
p.versioner = factory(repoCfg.Versioning.Params)
p.versioner = factory(repoCfg.ID, repoCfg.Directory, repoCfg.Versioning.Params)
}
if slots > 0 {
@ -632,7 +632,7 @@ func (p *puller) handleEmptyBlock(b bqBlock) {
if debug {
l.Debugln("pull: deleting with versioner")
}
if err := p.versioner.Archive(p.repoCfg.Directory, of.filepath); err == nil {
if err := p.versioner.Archive(of.filepath); err == nil {
p.model.updateLocal(p.repoCfg.ID, f)
} else if debug {
l.Debugln("pull: error:", err)
@ -762,7 +762,7 @@ func (p *puller) closeFile(f protocol.FileInfo) {
osutil.ShowFile(of.temp)
if p.versioner != nil {
err := p.versioner.Archive(p.repoCfg.Directory, of.filepath)
err := p.versioner.Archive(of.filepath)
if err != nil {
if debug {
l.Debugf("pull: error: %q / %q: %v", p.repoCfg.ID, f.Name, err)

View File

@ -21,18 +21,20 @@ func init() {
// The type holds our configuration
type Simple struct {
keep int
keep int
repoPath string
}
// The constructor function takes a map of parameters and creates the type.
func NewSimple(params map[string]string) Versioner {
func NewSimple(repoID, repoPath string, params map[string]string) Versioner {
keep, err := strconv.Atoi(params["keep"])
if err != nil {
keep = 5 // A reasonable default
}
s := Simple{
keep: keep,
keep: keep,
repoPath: repoPath,
}
if debug {
@ -43,7 +45,7 @@ func NewSimple(params map[string]string) Versioner {
// Move away the named file to a version archive. If this function returns
// nil, the named file does not exist any more (has been archived).
func (v Simple) Archive(repoPath, filePath string) error {
func (v Simple) Archive(filePath string) error {
_, err := os.Stat(filePath)
if err != nil && os.IsNotExist(err) {
if debug {
@ -52,7 +54,7 @@ func (v Simple) Archive(repoPath, filePath string) error {
return nil
}
versionsDir := filepath.Join(repoPath, ".stversions")
versionsDir := filepath.Join(v.repoPath, ".stversions")
_, err = os.Stat(versionsDir)
if err != nil {
if os.IsNotExist(err) {
@ -71,7 +73,7 @@ func (v Simple) Archive(repoPath, filePath string) error {
}
file := filepath.Base(filePath)
inRepoPath, err := filepath.Rel(repoPath, filepath.Dir(filePath))
inRepoPath, err := filepath.Rel(v.repoPath, filepath.Dir(filePath))
if err != nil {
return err
}

View File

@ -7,7 +7,7 @@
package versioner
type Versioner interface {
Archive(repoPath, filePath string) error
Archive(filePath string) error
}
var Factories = map[string]func(map[string]string) Versioner{}
var Factories = map[string]func(repoID string, repoDir string, params map[string]string) Versioner{}