add os stat to file validate method

This commit is contained in:
cyber-dream 2023-02-08 21:48:19 +03:00
parent 1a2732df7a
commit 0cef129db6

View File

@ -68,7 +68,7 @@ type FileValidationInfo struct {
SHA1 string SHA1 string
} }
func ValidateFile(filePath string) (FileValidationInfo, error) { func ValidateFile(filePath string) (*FileValidationInfo, error) {
info := FileValidationInfo{ info := FileValidationInfo{
Path: filePath, Path: filePath,
FileInfo: nil, FileInfo: nil,
@ -76,13 +76,19 @@ func ValidateFile(filePath string) (FileValidationInfo, error) {
} }
info.Path = filePath info.Path = filePath
stat, err := os.Stat(filePath)
if err != nil {
return &info, err
}
info.FileInfo = stat
hash, err := GetFileHash(filePath) hash, err := GetFileHash(filePath)
if err != nil { if err != nil {
return info, err return &info, err
} }
info.SHA1 = hash info.SHA1 = hash
return info, nil return &info, nil
} }
func GetFileHash(filePath string) (string, error) { func GetFileHash(filePath string) (string, error) {