mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-02-02 21:27:15 +08:00
fix zero file sha1 calc error
This commit is contained in:
parent
8ac48bbda5
commit
b36b14e03a
@ -312,10 +312,11 @@ func (f *FileActionTask) uploadFile(ctx context.Context) error {
|
||||
sha1Str = f.syncItem.LocalFile.Sha1Hash
|
||||
} else {
|
||||
logger.Verbosef("正在计算文件SHA1: %s\n", localFile.Path)
|
||||
localFile.Sum(localfile.CHECKSUM_SHA1)
|
||||
sha1Str = localFile.SHA1
|
||||
if localFile.Length == 0 {
|
||||
sha1Str = aliyunpan.DefaultZeroSizeFileContentHash
|
||||
} else {
|
||||
localFile.Sum(localfile.CHECKSUM_SHA1)
|
||||
sha1Str = localFile.SHA1
|
||||
}
|
||||
f.syncItem.LocalFile.Sha1Hash = sha1Str
|
||||
f.syncFileDb.Update(f.syncItem)
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
mapset "github.com/deckarep/golang-set"
|
||||
"github.com/tickstep/aliyunpan-api/aliyunpan"
|
||||
"github.com/tickstep/aliyunpan/internal/localfile"
|
||||
"github.com/tickstep/aliyunpan/internal/waitgroup"
|
||||
"github.com/tickstep/aliyunpan/library/collection"
|
||||
@ -430,14 +431,18 @@ func (f *FileActionTaskManager) doFileDiffRoutine(panFiles PanFileList, localFil
|
||||
|
||||
if localFile.Sha1Hash == "" {
|
||||
// calc sha1
|
||||
fileSum := localfile.NewLocalFileEntity(localFile.Path)
|
||||
err := fileSum.OpenPath()
|
||||
if err != nil {
|
||||
logger.Verbosef("文件不可读, 错误信息: %s, 跳过...\n", err)
|
||||
if localFile.FileSize == 0 {
|
||||
localFile.Sha1Hash = aliyunpan.DefaultZeroSizeFileContentHash
|
||||
} else {
|
||||
fileSum := localfile.NewLocalFileEntity(localFile.Path)
|
||||
err := fileSum.OpenPath()
|
||||
if err != nil {
|
||||
logger.Verbosef("文件不可读, 错误信息: %s, 跳过...\n", err)
|
||||
}
|
||||
fileSum.Sum(localfile.CHECKSUM_SHA1) // block operation
|
||||
localFile.Sha1Hash = fileSum.SHA1
|
||||
fileSum.Close()
|
||||
}
|
||||
fileSum.Sum(localfile.CHECKSUM_SHA1) // block operation
|
||||
localFile.Sha1Hash = fileSum.SHA1
|
||||
fileSum.Close()
|
||||
|
||||
// save sha1
|
||||
f.task.localFileDb.Update(localFile)
|
||||
|
Loading…
Reference in New Issue
Block a user