hash too long

This commit is contained in:
dengqn 2024-08-30 09:15:24 +08:00
parent 22425fc471
commit 53cc29b44f
2 changed files with 9 additions and 6 deletions

4
lv.go
View File

@ -122,9 +122,11 @@ func add() {
Created: time.Now().UnixMilli(),
Version: max + 1,
})
fmt.Println("meta:", meta)
storage.SaveMeta(util.ToHashHex(fullPath), meta)
storage.CopyData(fullPath, meta.Versions[len(meta.Versions)-1])
fmt.Println("version copied")
}
func del() {

View File

@ -1,12 +1,13 @@
package util
import (
"crypto/sha1"
"encoding/hex"
"crypto/md5"
"fmt"
"io"
)
func ToHashHex(filePath string) string {
s1 := sha1.New()
buf := s1.Sum([]byte(filePath))
return hex.EncodeToString(buf)
h := md5.New()
io.WriteString(h, filePath)
return fmt.Sprintf("%x", h.Sum(nil))
}