Use md5 hash of filename for temporary file (fixes #1786)

This commit is contained in:
Jakob Borg 2015-05-09 21:37:09 +02:00 committed by Lode Hoste
parent bcf51aed83
commit 285dcc30cf
4 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,7 @@
package model
import (
"crypto/md5"
"fmt"
"path/filepath"
"strings"
@ -25,7 +26,9 @@ func (t tempNamer) IsTemporary(name string) bool {
}
func (t tempNamer) TempName(name string) string {
hash := md5.New()
hash.Write([]byte(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)
}

View File

@ -9,6 +9,7 @@
package model
import (
"crypto/md5"
"fmt"
"path/filepath"
"strings"
@ -25,7 +26,9 @@ func (t tempNamer) IsTemporary(name string) bool {
}
func (t tempNamer) TempName(name string) string {
hash := md5.New()
hash.Write([]byte(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)
}