Also check file size when determining if file is unchanged (fixes #1058)

This commit is contained in:
Jakob Borg 2014-12-29 14:15:08 +01:00
parent 229b218203
commit f762a12d18
2 changed files with 44 additions and 1 deletions

View File

@ -254,9 +254,11 @@ func (w *Walker) walkAndHashFiles(fchan chan protocol.FileInfo) filepath.WalkFun
// - was not a directory previously (since it's a file now)
// - was not a symlink (since it's a file now)
// - was not invalid (since it looks valid now)
// - has the same size as previously
cf := w.CurrentFiler.CurrentFile(rn)
permUnchanged := w.IgnorePerms || !cf.HasPermissionBits() || PermsEqual(cf.Flags, uint32(info.Mode()))
if permUnchanged && !cf.IsDeleted() && cf.Modified == info.ModTime().Unix() && !cf.IsDirectory() && !cf.IsSymlink() && !cf.IsInvalid() {
if permUnchanged && !cf.IsDeleted() && cf.Modified == info.ModTime().Unix() && !cf.IsDirectory() &&
!cf.IsSymlink() && !cf.IsInvalid() && cf.Size() == info.Size() {
return nil
}

View File

@ -20,6 +20,7 @@ package integration
import (
"fmt"
"log"
"os"
"testing"
"time"
@ -103,6 +104,20 @@ func testSyncCluster(t *testing.T) {
t.Fatal(err)
}
// We'll use this file for appending data without modifying the time stamp.
fd, err := os.Create("s1/appendfile")
if err != nil {
t.Fatal(err)
}
_, err = fd.WriteString("hello\n")
if err != nil {
t.Fatal(err)
}
err = fd.Close()
if err != nil {
t.Fatal(err)
}
err = generateFiles("s2", 1000, 21, "../LICENSE")
if err != nil {
t.Fatal(err)
@ -170,6 +185,32 @@ func testSyncCluster(t *testing.T) {
break
}
// Alter the "appendfile" without changing it's modification time. Sneaky!
fi, err := os.Stat("s1/appendfile")
if err != nil {
t.Fatal(err)
}
fd, err := os.OpenFile("s1/appendfile", os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
t.Fatal(err)
}
_, err = fd.Seek(0, os.SEEK_END)
if err != nil {
t.Fatal(err)
}
_, err = fd.WriteString("more data\n")
if err != nil {
t.Fatal(err)
}
err = fd.Close()
if err != nil {
t.Fatal(err)
}
err = os.Chtimes("s1/appendfile", fi.ModTime(), fi.ModTime())
if err != nil {
t.Fatal(err)
}
// Prepare the expected state of folders after the sync
e1 = directoryContents("s1")
e2 = directoryContents("s12-1")