Skip to content

Commit cf53015

Browse files
authored
Merge pull request #153 from tomfaulhaber/empty-file-fix
Fix sameFile() to recognize empty files as the same
2 parents d3ef23f + 5a33969 commit cf53015

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

fs/diff_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ func TestSimpleDiff(t *testing.T) {
7272
}
7373
}
7474

75+
func TestEmptyFileDiff(t *testing.T) {
76+
skipDiffTestOnWindows(t)
77+
tt := time.Now().Truncate(time.Second)
78+
l1 := fstest.Apply(
79+
fstest.CreateDir("/etc", 0755),
80+
fstest.CreateFile("/etc/empty", []byte(""), 0644),
81+
fstest.Chtimes("/etc/empty", tt, tt),
82+
)
83+
l2 := fstest.Apply()
84+
diff := []TestChange{}
85+
86+
if err := testDiffWithBase(l1, l2, diff); err != nil {
87+
t.Fatalf("Failed diff with base: %+v", err)
88+
}
89+
}
90+
7591
func TestNestedDeletion(t *testing.T) {
7692
skipDiffTestOnWindows(t)
7793
l1 := fstest.Apply(

fs/path.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func sameFile(f1, f2 *currentPath) (bool, error) {
122122
eq, err = compareSymlinkTarget(f1.fullPath, f2.fullPath)
123123
} else if f1.f.Size() > 0 {
124124
eq, err = compareFileContent(f1.fullPath, f2.fullPath)
125+
} else {
126+
eq, err = true, nil // if file sizes are zero length, the files are the same by definition
125127
}
126128
if err != nil || !eq {
127129
return eq, err

0 commit comments

Comments
 (0)