mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
lib/versioner: Minor fixes in comments and error message (#9031)
* lib/versioner: Factor out DefaultPath constant. Replace several instances where .stversions is named literally to all use the same definition in the versioner package. Exceptions are the packages where a cyclic dependency on versioner is impossible, or some tests which combine the versions base path with other components. * lib/versioner: Fix comment about trash can in simple versioner. * lib/versioner: Fix wrong versioning type string in error message. The error message shows the folder type instead of the versioning type, although the correct field is used in the comparison.
This commit is contained in:
parent
8b87cd5229
commit
a8cacdca94
@ -293,7 +293,8 @@ func NewFilesystem(fsType FilesystemType, uri string, opts ...Option) Filesystem
|
||||
// root, represents an internal file that should always be ignored. The file
|
||||
// path must be clean (i.e., in canonical shortest form).
|
||||
func IsInternal(file string) bool {
|
||||
// fs cannot import config, so we hard code .stfolder here (config.DefaultMarkerName)
|
||||
// fs cannot import config or versioner, so we hard code .stfolder
|
||||
// (config.DefaultMarkerName) and .stversions (versioner.DefaultPath)
|
||||
internals := []string{".stfolder", ".stignore", ".stversions"}
|
||||
for _, internal := range internals {
|
||||
if file == internal {
|
||||
|
@ -399,7 +399,7 @@ func (m *model) addAndStartFolderLockedWithIgnores(cfg config.FolderConfiguratio
|
||||
// These are our metadata files, and they should always be hidden.
|
||||
ffs := cfg.Filesystem(nil)
|
||||
_ = ffs.Hide(config.DefaultMarkerName)
|
||||
_ = ffs.Hide(".stversions")
|
||||
_ = ffs.Hide(versioner.DefaultPath)
|
||||
_ = ffs.Hide(".stignore")
|
||||
|
||||
var ver versioner.Versioner
|
||||
|
@ -2647,7 +2647,7 @@ func TestVersionRestore(t *testing.T) {
|
||||
file = filepath.FromSlash(file)
|
||||
}
|
||||
tag := version.In(time.Local).Truncate(time.Second).Format(versioner.TimeFormat)
|
||||
taggedName := filepath.Join(".stversions", versioner.TagFilename(file, tag))
|
||||
taggedName := filepath.Join(versioner.DefaultPath, versioner.TagFilename(file, tag))
|
||||
fd, err := filesystem.Open(file)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@ -2680,7 +2680,7 @@ func TestVersionRestore(t *testing.T) {
|
||||
}
|
||||
for _, version := range versions {
|
||||
if version.VersionTime.Equal(beforeRestore) || version.VersionTime.After(beforeRestore) {
|
||||
fd, err := filesystem.Open(".stversions/" + versioner.TagFilename(file, version.VersionTime.Format(versioner.TimeFormat)))
|
||||
fd, err := filesystem.Open(versioner.DefaultPath + "/" + versioner.TagFilename(file, version.VersionTime.Format(versioner.TimeFormat)))
|
||||
must(t, err)
|
||||
defer fd.Close()
|
||||
|
||||
|
@ -32,7 +32,7 @@ type simple struct {
|
||||
func newSimple(cfg config.FolderConfiguration) Versioner {
|
||||
var keep, err = strconv.Atoi(cfg.Versioning.Params["keep"])
|
||||
cleanoutDays, _ := strconv.Atoi(cfg.Versioning.Params["cleanoutDays"])
|
||||
// On error we default to 0, "do not clean out the trash can"
|
||||
// On error we default to 0, "do not clean out the versioned items"
|
||||
|
||||
if err != nil {
|
||||
keep = 5 // A reasonable default
|
||||
|
@ -81,7 +81,7 @@ func TestSimpleVersioningVersionCount(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
n, err := fs.DirNames(".stversions")
|
||||
n, err := fs.DirNames(DefaultPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ var (
|
||||
errFileAlreadyExists = errors.New("file already exists")
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultPath = ".stversions"
|
||||
)
|
||||
|
||||
// TagFilename inserts ~tag just before the extension of the filename.
|
||||
func TagFilename(name, tag string) string {
|
||||
dir, file := filepath.Dir(name), filepath.Base(name)
|
||||
@ -258,7 +262,7 @@ func restoreFile(method fs.CopyRangeMethod, src, dst fs.Filesystem, filePath str
|
||||
func versionerFsFromFolderCfg(cfg config.FolderConfiguration) (versionsFs fs.Filesystem) {
|
||||
folderFs := cfg.Filesystem(nil)
|
||||
if cfg.Versioning.FSPath == "" {
|
||||
versionsFs = fs.NewFilesystem(folderFs.Type(), filepath.Join(folderFs.URI(), ".stversions"))
|
||||
versionsFs = fs.NewFilesystem(folderFs.Type(), filepath.Join(folderFs.URI(), DefaultPath))
|
||||
} else if cfg.Versioning.FSType == fs.FilesystemTypeBasic && !filepath.IsAbs(cfg.Versioning.FSPath) {
|
||||
// We only know how to deal with relative folders for basic filesystems, as that's the only one we know
|
||||
// how to check if it's absolute or relative.
|
||||
|
@ -44,7 +44,7 @@ const (
|
||||
func New(cfg config.FolderConfiguration) (Versioner, error) {
|
||||
fac, ok := factories[cfg.Versioning.Type]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("requested versioning type %q does not exist", cfg.Type)
|
||||
return nil, fmt.Errorf("requested versioning type %q does not exist", cfg.Versioning.Type)
|
||||
}
|
||||
|
||||
return &versionerWithErrorContext{
|
||||
|
Loading…
Reference in New Issue
Block a user