mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 15:17:25 +00:00
parent
b5082f6af8
commit
bae6d5f375
@ -122,8 +122,8 @@ var locationTemplates = map[LocationEnum]string{
|
|||||||
Database: "${data}/" + LevelDBDir,
|
Database: "${data}/" + LevelDBDir,
|
||||||
LogFile: "${data}/syncthing.log", // --logfile on Windows
|
LogFile: "${data}/syncthing.log", // --logfile on Windows
|
||||||
CsrfTokens: "${data}/csrftokens.txt",
|
CsrfTokens: "${data}/csrftokens.txt",
|
||||||
PanicLog: "${data}/panic-${timestamp}.log",
|
PanicLog: "${data}/panic-%{timestamp}.log",
|
||||||
AuditLog: "${data}/audit-${timestamp}.log",
|
AuditLog: "${data}/audit-%{timestamp}.log",
|
||||||
GUIAssets: "${config}/gui",
|
GUIAssets: "${config}/gui",
|
||||||
DefFolder: "${userHome}/Sync",
|
DefFolder: "${userHome}/Sync",
|
||||||
}
|
}
|
||||||
@ -285,14 +285,18 @@ func userHomeDir() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetTimestamped(key LocationEnum) string {
|
func GetTimestamped(key LocationEnum) string {
|
||||||
// We take the roundtrip via "${timestamp}" instead of passing the path
|
return getTimestampedAt(key, time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTimestampedAt(key LocationEnum, when time.Time) string {
|
||||||
|
// We take the roundtrip via "%{timestamp}" instead of passing the path
|
||||||
// directly through time.Format() to avoid issues when the path we are
|
// directly through time.Format() to avoid issues when the path we are
|
||||||
// expanding contains numbers; otherwise for example
|
// expanding contains numbers; otherwise for example
|
||||||
// /home/user2006/.../panic-20060102-150405.log would get both instances of
|
// /home/user2006/.../panic-20060102-150405.log would get both instances of
|
||||||
// 2006 replaced by 2015...
|
// 2006 replaced by 2015...
|
||||||
tpl := locations[key]
|
tpl := locations[key]
|
||||||
now := time.Now().Format("20060102-150405")
|
timestamp := when.Format("20060102-150405")
|
||||||
return strings.ReplaceAll(tpl, "${timestamp}", now)
|
return strings.ReplaceAll(tpl, "%{timestamp}", timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileExists(path string) bool {
|
func fileExists(path string) bool {
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
package locations
|
package locations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
@ -100,3 +102,11 @@ func TestUnixDataDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetTimestamped(t *testing.T) {
|
||||||
|
s := getTimestampedAt(PanicLog, time.Date(2023, 10, 25, 21, 47, 0, 0, time.UTC))
|
||||||
|
exp := "panic-20231025-214700.log"
|
||||||
|
if file := filepath.Base(s); file != exp {
|
||||||
|
t.Errorf("got %q, expected %q", file, exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user