versioner.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. "os"
  11. "path/filepath"
  12. "runtime"
  13. )
  14. type Versioner interface {
  15. Archive(filePath string) error
  16. }
  17. var Factories = map[string]func(folderID string, folderDir string, params map[string]string) Versioner{}
  18. const (
  19. TimeFormat = "20060102-150405"
  20. 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
  21. )
  22. func cleanSymlinks(dir string) {
  23. if runtime.GOOS == "windows" {
  24. // We don't do symlinks on Windows. Additionally, there may
  25. // be things that look like symlinks that are not, which we
  26. // should leave alone. Deduplicated files, for example.
  27. return
  28. }
  29. filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
  30. if err != nil {
  31. return err
  32. }
  33. if info.Mode()&os.ModeSymlink != 0 {
  34. l.Infoln("Removing incorrectly versioned symlink", path)
  35. os.Remove(path)
  36. return filepath.SkipDir
  37. }
  38. return nil
  39. })
  40. }