From a165838cbddcc1445619202fa4d01f7b9b996e56 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 27 Jun 2016 11:47:40 +0000 Subject: [PATCH] lib/model: Decrease max temp filename length (fixes #3338, fixes #3355) GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3356 --- lib/model/tempname.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/model/tempname.go b/lib/model/tempname.go index 54a5fd09..aa95ae67 100644 --- a/lib/model/tempname.go +++ b/lib/model/tempname.go @@ -20,6 +20,11 @@ type tempNamer struct { var defTempNamer tempNamer +// Real filesystems usually handle 255 bytes. encfs has varying and +// confusing file name limits. We take a safe way out and switch to hashing +// quite early. +const maxFilenameLength = 160 - len(".syncthing.") - len(".tmp") + func init() { if runtime.GOOS == "windows" { defTempNamer = tempNamer{"~syncthing~"} @@ -35,7 +40,7 @@ func (t tempNamer) IsTemporary(name string) bool { func (t tempNamer) TempName(name string) string { tdir := filepath.Dir(name) tbase := filepath.Base(name) - if len(tbase) > 240 { + if len(tbase) > maxFilenameLength { hash := md5.New() hash.Write([]byte(name)) tbase = fmt.Sprintf("%x", hash.Sum(nil))