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:
André Colomb 2023-08-09 09:10:06 +02:00 committed by GitHub
parent 8b87cd5229
commit a8cacdca94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 8 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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)
}

View File

@ -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.

View File

@ -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{