tempname.go 662 B

1234567891011121314151617181920212223242526272829
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. // All rights reserved. Use of this source code is governed by an MIT-style
  3. // license that can be found in the LICENSE file.
  4. // +build !windows
  5. package model
  6. import (
  7. "fmt"
  8. "path/filepath"
  9. "strings"
  10. )
  11. type tempNamer struct {
  12. prefix string
  13. }
  14. var defTempNamer = tempNamer{".syncthing"}
  15. func (t tempNamer) IsTemporary(name string) bool {
  16. return strings.HasPrefix(filepath.Base(name), t.prefix)
  17. }
  18. func (t tempNamer) TempName(name string) string {
  19. tdir := filepath.Dir(name)
  20. tname := fmt.Sprintf("%s.%s", t.prefix, filepath.Base(name))
  21. return filepath.Join(tdir, tname)
  22. }