Skip to content

Commit

Permalink
Fix the problem that when comparing with the BinaryContents compare m…
Browse files Browse the repository at this point in the history
…ethod, the contents of the files are identical, but if one side is a symbolic link, it is judged to be different. refs #1976
  • Loading branch information
sdottaka committed Aug 11, 2023
1 parent ee01676 commit dfcaf93
Show file tree
Hide file tree
Showing 35 changed files with 98 additions and 5 deletions.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,35 @@ Plugins/src_VCPP/WatchBeginningOfLog/WatchBeginningOfLog.h
Plugins/src_VCPP/WatchEndOfLog/WatchEndOfLog.h
Tools/Scripts/MenuResources.txt
Tools/Scripts/UnusedResources.txt
Testing/Data/Symlink/Dir1/s1_s0.txt
Testing/Data/Symlink/Dir1/s1_s1.txt
Testing/Data/Symlink/Dir1/sf12_diff_s01.txt
Testing/Data/Symlink/Dir1/sf12_diff_s10.txt
Testing/Data/Symlink/Dir1/sf12_diff_s11.txt
Testing/Data/Symlink/Dir1/sf12_diff_s12.txt
Testing/Data/Symlink/Dir1/sf12_diff_s21.txt
Testing/Data/Symlink/Dir1/sf12_same_s00.txt
Testing/Data/Symlink/Dir1/sf12_same_s11.txt
Testing/Data/Symlink/Dir1/ss12_diff_s01.txt
Testing/Data/Symlink/Dir1/ss12_diff_s10.txt
Testing/Data/Symlink/Dir1/ss12_diff_s11.txt
Testing/Data/Symlink/Dir1/ss12_diff_s12.txt
Testing/Data/Symlink/Dir1/ss12_diff_s21.txt
Testing/Data/Symlink/Dir1/ss12_same_s00.txt
Testing/Data/Symlink/Dir1/ss12_same_s11.txt
Testing/Data/Symlink/Dir2/fs12_diff_s01.txt
Testing/Data/Symlink/Dir2/fs12_diff_s10.txt
Testing/Data/Symlink/Dir2/fs12_diff_s11.txt
Testing/Data/Symlink/Dir2/fs12_diff_s12.txt
Testing/Data/Symlink/Dir2/fs12_diff_s21.txt
Testing/Data/Symlink/Dir2/fs12_same_s00.txt
Testing/Data/Symlink/Dir2/fs12_same_s11.txt
Testing/Data/Symlink/Dir2/s2_s0.txt
Testing/Data/Symlink/Dir2/s2_s1.txt
Testing/Data/Symlink/Dir2/ss12_diff_s01.txt
Testing/Data/Symlink/Dir2/ss12_diff_s10.txt
Testing/Data/Symlink/Dir2/ss12_diff_s11.txt
Testing/Data/Symlink/Dir2/ss12_diff_s12.txt
Testing/Data/Symlink/Dir2/ss12_diff_s21.txt
Testing/Data/Symlink/Dir2/ss12_same_s00.txt
Testing/Data/Symlink/Dir2/ss12_same_s11.txt
17 changes: 12 additions & 5 deletions Src/CompareEngines/BinaryCompare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ static int compare_files(const String& file1, const String& file2, IAbortable *p
{
if (size1 < 0 || size2 < 0)
code = DIFFCODE::CMPERR;
else
else if (size1 == size2)
code = DIFFCODE::SAME;
else
code = DIFFCODE::DIFF;
break;
}
if (size1 != size2 || memcmp(buf1, buf2, size1) != 0)
Expand Down Expand Up @@ -87,12 +89,16 @@ int BinaryCompare::CompareFiles(const PathContext& files, const DIFFITEM &di) co
switch (files.GetSize())
{
case 2:
return di.diffFileInfo[0].size != di.diffFileInfo[1].size ?
// If the file size is 0, don't immediately assume that there is a difference even if the files have different sizes, because of possible symlinks.
return (di.diffFileInfo[0].size != di.diffFileInfo[1].size &&
di.diffFileInfo[0].size != 0 && di.diffFileInfo[1].size != 0) ?
DIFFCODE::DIFF : compare_files(files[0], files[1], m_piAbortable);
case 3:
unsigned code10 = (di.diffFileInfo[1].size != di.diffFileInfo[0].size) ?
unsigned code10 = (di.diffFileInfo[1].size != di.diffFileInfo[0].size &&
di.diffFileInfo[1].size != 0 && di.diffFileInfo[0].size != 0) ?
DIFFCODE::DIFF : compare_files(files[1], files[0], m_piAbortable);
unsigned code12 = (di.diffFileInfo[1].size != di.diffFileInfo[2].size) ?
unsigned code12 = (di.diffFileInfo[1].size != di.diffFileInfo[2].size &&
di.diffFileInfo[1].size != 0 && di.diffFileInfo[2].size != 0) ?
DIFFCODE::DIFF : compare_files(files[1], files[2], m_piAbortable);
unsigned code02 = DIFFCODE::SAME;
if (code10 == DIFFCODE::SAME && code12 == DIFFCODE::SAME)
Expand All @@ -103,7 +109,8 @@ int BinaryCompare::CompareFiles(const PathContext& files, const DIFFITEM &di) co
return DIFFCODE::DIFF | DIFFCODE::DIFF1STONLY;
else if (code10 == DIFFCODE::DIFF && code12 == DIFFCODE::DIFF)
{
code02 = di.diffFileInfo[0].size != di.diffFileInfo[2].size ?
code02 = (di.diffFileInfo[0].size != di.diffFileInfo[2].size &&
di.diffFileInfo[0].size != 0 && di.diffFileInfo[2].size != 0) ?
DIFFCODE::DIFF : compare_files(files[0], files[2], m_piAbortable);
if (code02 == DIFFCODE::SAME)
return DIFFCODE::DIFF | DIFFCODE::DIFF2NDONLY;
Expand Down
32 changes: 32 additions & 0 deletions Testing/Data/Symlink/CreateSymlink.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
mklink %~dp0\Dir1\s1_s0.txt %~dp0\Dir1\f1_s0.txt
mklink %~dp0\Dir1\s1_s1.txt %~dp0\Dir1\f1_s1.txt
mklink %~dp0\Dir2\s2_s0.txt %~dp0\Dir2\f2_s0.txt
mklink %~dp0\Dir2\s2_s1.txt %~dp0\Dir2\f2_s1.txt
mklink %~dp0\Dir1\sf12_same_s00.txt %~dp0\Dir1\ff12_same_s00.txt
mklink %~dp0\Dir1\sf12_same_s11.txt %~dp0\Dir1\ff12_same_s11.txt
mklink %~dp0\Dir1\sf12_diff_s01.txt %~dp0\Dir1\ff12_diff_s01.txt
mklink %~dp0\Dir1\sf12_diff_s10.txt %~dp0\Dir1\ff12_diff_s10.txt
mklink %~dp0\Dir1\sf12_diff_s11.txt %~dp0\Dir1\ff12_diff_s11.txt
mklink %~dp0\Dir1\sf12_diff_s12.txt %~dp0\Dir1\ff12_diff_s12.txt
mklink %~dp0\Dir1\sf12_diff_s21.txt %~dp0\Dir1\ff12_diff_s21.txt
mklink %~dp0\Dir2\fs12_same_s00.txt %~dp0\Dir2\ff12_same_s00.txt
mklink %~dp0\Dir2\fs12_same_s11.txt %~dp0\Dir2\ff12_same_s11.txt
mklink %~dp0\Dir2\fs12_diff_s01.txt %~dp0\Dir2\ff12_diff_s01.txt
mklink %~dp0\Dir2\fs12_diff_s10.txt %~dp0\Dir2\ff12_diff_s10.txt
mklink %~dp0\Dir2\fs12_diff_s11.txt %~dp0\Dir2\ff12_diff_s11.txt
mklink %~dp0\Dir2\fs12_diff_s12.txt %~dp0\Dir2\ff12_diff_s12.txt
mklink %~dp0\Dir2\fs12_diff_s21.txt %~dp0\Dir2\ff12_diff_s21.txt
mklink %~dp0\Dir1\ss12_same_s00.txt %~dp0\Dir1\ff12_same_s00.txt
mklink %~dp0\Dir1\ss12_same_s11.txt %~dp0\Dir1\ff12_same_s11.txt
mklink %~dp0\Dir1\ss12_diff_s01.txt %~dp0\Dir1\ff12_diff_s01.txt
mklink %~dp0\Dir1\ss12_diff_s10.txt %~dp0\Dir1\ff12_diff_s10.txt
mklink %~dp0\Dir1\ss12_diff_s11.txt %~dp0\Dir1\ff12_diff_s11.txt
mklink %~dp0\Dir1\ss12_diff_s12.txt %~dp0\Dir1\ff12_diff_s12.txt
mklink %~dp0\Dir1\ss12_diff_s21.txt %~dp0\Dir1\ff12_diff_s21.txt
mklink %~dp0\Dir2\ss12_same_s00.txt %~dp0\Dir2\ff12_same_s00.txt
mklink %~dp0\Dir2\ss12_same_s11.txt %~dp0\Dir2\ff12_same_s11.txt
mklink %~dp0\Dir2\ss12_diff_s01.txt %~dp0\Dir2\ff12_diff_s01.txt
mklink %~dp0\Dir2\ss12_diff_s10.txt %~dp0\Dir2\ff12_diff_s10.txt
mklink %~dp0\Dir2\ss12_diff_s11.txt %~dp0\Dir2\ff12_diff_s11.txt
mklink %~dp0\Dir2\ss12_diff_s12.txt %~dp0\Dir2\ff12_diff_s12.txt
mklink %~dp0\Dir2\ss12_diff_s21.txt %~dp0\Dir2\ff12_diff_s21.txt
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/f1_s1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/ff12_diff_s10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/ff12_diff_s11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/ff12_diff_s12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/ff12_diff_s21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AB
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/ff12_same_s11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/fs12_diff_s10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/fs12_diff_s11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/fs12_diff_s12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/fs12_diff_s21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AB
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir1/fs12_same_s11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/f2_s1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/ff12_diff_s01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/ff12_diff_s11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/ff12_diff_s12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AB
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/ff12_diff_s21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/ff12_same_s11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/sf12_diff_s01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/sf12_diff_s11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/sf12_diff_s12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AB
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/sf12_diff_s21.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B
Empty file.
1 change: 1 addition & 0 deletions Testing/Data/Symlink/Dir2/sf12_same_s11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A

0 comments on commit dfcaf93

Please sign in to comment.