Update condition for safe md5 check

This commit is contained in:
2025-09-02 22:12:30 +07:00
parent c26ecf70fe
commit 4d9310bc35
3 changed files with 8 additions and 14 deletions

View File

@@ -30,12 +30,10 @@ func safePartialMD5(path string) (string, error) {
return "", err
}
size := fi.Size()
modTime := fi.ModTime().UnixNano()
h := md5.New()
binary.Write(h, binary.LittleEndian, size)
binary.Write(h, binary.LittleEndian, modTime)
binary.Write(h, binary.LittleEndian, fi.Mode())
buf := make([]byte, 4096)
@@ -99,9 +97,7 @@ func DiffFolders(oldPath, newPath string) (*DiffResult, error) {
workers := runtime.NumCPU() * 2
for i := 0; i < workers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
for job := range jobs {
rel, oldFile, newFile := job[0], job[1], job[2]
oldHash, _ := safePartialMD5(oldFile)
@@ -113,7 +109,7 @@ func DiffFolders(oldPath, newPath string) (*DiffResult, error) {
}
bar.Add(1)
}
}()
})
}
for rel, oldFile := range oldFiles {

View File

@@ -16,18 +16,18 @@ type HdiffFile struct {
}
func MakeHdiffFile(oldPath string, newPath string, changedFiles []string) error {
delFile, err := os.Create("hdiff/hdifffiles.txt")
diffFile, err := os.Create("hdiff/hdifffiles.txt")
if err != nil {
return err
}
defer delFile.Close()
defer diffFile.Close()
for _, f := range changedFiles {
data, err := json.Marshal(HdiffFile{RemoteName: f})
if err != nil {
return err
}
fmt.Fprintln(delFile, string(data))
fmt.Fprintln(diffFile, string(data))
}
bar := progressbar.NewOptions(len(changedFiles),
@@ -37,10 +37,8 @@ func MakeHdiffFile(oldPath string, newPath string, changedFiles []string) error
progressbar.OptionSetPredictTime(true),
)
workers := runtime.NumCPU() / 2
if workers < 2 {
workers = 2
}
workers := runtime.NumCPU()
jobs := make(chan string, len(changedFiles))
var wg sync.WaitGroup

View File

@@ -104,7 +104,7 @@ func ZipWith7za(src, dest string) error {
return err
}
args := []string{"a", "-tzip", "-mx=1", "-mmt=on", destAbs}
args := []string{"a", "-tzip", "-mx=3", "-mmt=on", destAbs}
for _, f := range files {
args = append(args, f.Name())
}