Browse Source

Merge pull request #1149 from syncthing/fix-1058

Also check file size when determining if file is unchanged (fixes #1058)
Audrius Butkevicius 10 năm trước cách đây
mục cha
commit
0f9550c747
2 tập tin đã thay đổi với 44 bổ sung1 xóa
  1. 3 1
      internal/scanner/walk.go
  2. 41 0
      test/sync_test.go

+ 3 - 1
internal/scanner/walk.go

@@ -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
 				}
 

+ 41 - 0
test/sync_test.go

@@ -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")