mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-12 16:26:37 +00:00
Use md5 hash of filename for temporary file (fixes #1786)
This commit is contained in:
parent
bcf51aed83
commit
285dcc30cf
@ -9,6 +9,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -25,7 +26,9 @@ func (t tempNamer) IsTemporary(name string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t tempNamer) TempName(name string) string {
|
func (t tempNamer) TempName(name string) string {
|
||||||
|
hash := md5.New()
|
||||||
|
hash.Write([]byte(name))
|
||||||
tdir := filepath.Dir(name)
|
tdir := filepath.Dir(name)
|
||||||
tname := fmt.Sprintf("%s.%s", t.prefix, filepath.Base(name))
|
tname := fmt.Sprintf("%s.%x", t.prefix, hash.Sum(nil))
|
||||||
return filepath.Join(tdir, tname)
|
return filepath.Join(tdir, tname)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -25,7 +26,9 @@ func (t tempNamer) IsTemporary(name string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t tempNamer) TempName(name string) string {
|
func (t tempNamer) TempName(name string) string {
|
||||||
|
hash := md5.New()
|
||||||
|
hash.Write([]byte(name))
|
||||||
tdir := filepath.Dir(name)
|
tdir := filepath.Dir(name)
|
||||||
tname := fmt.Sprintf("%s.%s.tmp", t.prefix, filepath.Base(name))
|
tname := fmt.Sprintf("%s.%x.tmp", t.prefix, hash.Sum(nil))
|
||||||
return filepath.Join(tdir, tname)
|
return filepath.Join(tdir, tname)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user