Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sameFile() to recognize empty files as the same #153

Merged
merged 2 commits into from
Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions fs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ func TestSimpleDiff(t *testing.T) {
}
}

func TestEmptyFileDiff(t *testing.T) {
skipDiffTestOnWindows(t)
tt := time.Now().Truncate(time.Second)
l1 := fstest.Apply(
fstest.CreateDir("/etc", 0755),
fstest.CreateFile("/etc/empty", []byte(""), 0644),
fstest.Chtimes("/etc/empty", tt, tt),
)
l2 := fstest.Apply()
diff := []TestChange{}

if err := testDiffWithBase(l1, l2, diff); err != nil {
t.Fatalf("Failed diff with base: %+v", err)
}
}

func TestNestedDeletion(t *testing.T) {
skipDiffTestOnWindows(t)
l1 := fstest.Apply(
Expand Down
2 changes: 2 additions & 0 deletions fs/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func sameFile(f1, f2 *currentPath) (bool, error) {
eq, err = compareSymlinkTarget(f1.fullPath, f2.fullPath)
} else if f1.f.Size() > 0 {
eq, err = compareFileContent(f1.fullPath, f2.fullPath)
} else {
eq, err = true, nil // if file sizes are zero length, the files are the same by definition
}
if err != nil || !eq {
return eq, err
Expand Down