mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
ac3b03881a
Also fixes an issue where the discovery cache call would only return the newest cache entry for a given device instead of the merged addresses from all cache entries (which is more useful). GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3344
34 lines
921 B
Go
34 lines
921 B
Go
// Copyright (C) 2014 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package versioner
|
|
|
|
import (
|
|
"path/filepath"
|
|
"regexp"
|
|
)
|
|
|
|
// Inserts ~tag just before the extension of the filename.
|
|
func taggedFilename(name, tag string) string {
|
|
dir, file := filepath.Dir(name), filepath.Base(name)
|
|
ext := filepath.Ext(file)
|
|
withoutExt := file[:len(file)-len(ext)]
|
|
return filepath.Join(dir, withoutExt+"~"+tag+ext)
|
|
}
|
|
|
|
var tagExp = regexp.MustCompile(`.*~([^~.]+)(?:\.[^.]+)?$`)
|
|
|
|
// Returns the tag from a filename, whether at the end or middle.
|
|
func filenameTag(path string) string {
|
|
match := tagExp.FindStringSubmatch(path)
|
|
// match is []string{"whole match", "submatch"} when successful
|
|
|
|
if len(match) != 2 {
|
|
return ""
|
|
}
|
|
return match[1]
|
|
}
|