versioner.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. // Package versioner implements common interfaces for file versioning and a
  7. // simple default versioning scheme.
  8. package versioner
  9. import (
  10. "fmt"
  11. "time"
  12. "github.com/syncthing/syncthing/lib/fs"
  13. )
  14. type Versioner interface {
  15. Archive(filePath string) error
  16. GetVersions() (map[string][]FileVersion, error)
  17. Restore(filePath string, versionTime time.Time) error
  18. }
  19. type FileVersion struct {
  20. VersionTime time.Time `json:"versionTime"`
  21. ModTime time.Time `json:"modTime"`
  22. Size int64 `json:"size"`
  23. }
  24. var Factories = map[string]func(folderID string, filesystem fs.Filesystem, params map[string]string) Versioner{}
  25. var ErrRestorationNotSupported = fmt.Errorf("version restoration not supported with the current versioner")
  26. const (
  27. TimeFormat = "20060102-150405"
  28. TimeGlob = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]" // glob pattern matching TimeFormat
  29. )