2828import java .nio .file .Files ;
2929import java .nio .file .Path ;
3030import java .nio .file .Paths ;
31+ import java .nio .file .StandardCopyOption ;
3132
3233import org .junit .jupiter .api .Test ;
3334import org .junit .jupiter .api .io .TempDir ;
@@ -106,7 +107,7 @@ public void testDirectoryAndFileContentEquals() throws Exception {
106107 * @throws Exception on test failure.
107108 */
108109 @ Test
109- public void testDirectoryAndFileContentEqualsDifferentFileSystems () throws Exception {
110+ public void testDirectoryAndFileContentEqualsDifferentFileSystemsFileVsZip () throws Exception {
110111 final Path dir1 = Paths .get ("src/test/resources/dir-equals-tests" );
111112 try (FileSystem fileSystem = FileSystems .newFileSystem (dir1 .resolveSibling (dir1 .getFileName () + ".zip" ), null )) {
112113 final Path dir2 = fileSystem .getPath ("/dir-equals-tests" );
@@ -115,6 +116,59 @@ public void testDirectoryAndFileContentEqualsDifferentFileSystems() throws Excep
115116 }
116117 }
117118
119+ /**
120+ * Tests IO-872 PathUtils.directoryAndFileContentEquals doesn't work across FileSystems.
121+ *
122+ * @throws Exception on test failure.
123+ */
124+ @ Test
125+ public void testDirectoryAndFileContentEqualsDifferentFileSystemsZipVsZip () throws Exception {
126+ final Path zipPath = Paths .get ("src/test/resources/dir-equals-tests.zip" );
127+ final Path zipCopy = temporaryFolder .toPath ().resolve ("copy.zip" );
128+ Files .copy (zipPath , zipCopy , StandardCopyOption .REPLACE_EXISTING );
129+ try (FileSystem fileSystem1 = FileSystems .newFileSystem (zipPath , null );
130+ FileSystem fileSystem2 = FileSystems .newFileSystem (zipCopy , null )) {
131+ final Path dir1 = fileSystem1 .getPath ("/dir-equals-tests" );
132+ final Path dir2 = fileSystem2 .getPath ("/dir-equals-tests" );
133+ // WindowsPath, UnixPath, and ZipPath equals() methods always return false if the argument is not of the same instance as itself.
134+ assertTrue (PathUtils .directoryAndFileContentEquals (dir1 , dir2 ));
135+ }
136+ }
137+
138+ /**
139+ * Tests IO-872 PathUtils.directoryAndFileContentEquals doesn't work across FileSystems.
140+ *
141+ * @throws Exception on test failure.
142+ */
143+ @ Test
144+ public void testDirectoryAndFileContentEqualsDifferentFileSystemsZipVsZipEmpty () throws Exception {
145+ final Path zipPath = Paths .get ("src/test/resources/dir-equals-tests.zip" );
146+ final Path emptyZip = Paths .get ("src/test/resources/org/apache/commons/io/empty.zip" );
147+ Files .copy (zipPath , emptyZip , StandardCopyOption .REPLACE_EXISTING );
148+ try (FileSystem fileSystem1 = FileSystems .newFileSystem (zipPath , null );
149+ FileSystem fileSystem2 = FileSystems .newFileSystem (emptyZip , null )) {
150+ final Path dir1 = fileSystem1 .getPath ("/dir-equals-tests" );
151+ final Path dir2 = fileSystem2 .getPath ("/" );
152+ // WindowsPath, UnixPath, and ZipPath equals() methods always return false if the argument is not of the same instance as itself.
153+ assertFalse (PathUtils .directoryAndFileContentEquals (dir1 , dir2 ));
154+ }
155+ try (FileSystem fileSystem1 = FileSystems .newFileSystem (zipPath , null );
156+ FileSystem fileSystem2 = FileSystems .newFileSystem (emptyZip , null )) {
157+ final Path dir1 = fileSystem1 .getPath ("/dir-equals-tests" );
158+ final Path dir2 = fileSystem2 .getRootDirectories ().iterator ().next ();
159+ // WindowsPath, UnixPath, and ZipPath equals() methods always return false if the argument is not of the same instance as itself.
160+ assertFalse (PathUtils .directoryAndFileContentEquals (dir1 , dir2 ));
161+ }
162+ final Path zipCopy = temporaryFolder .toPath ().resolve ("copy.zip" );
163+ Files .copy (emptyZip , zipCopy , StandardCopyOption .REPLACE_EXISTING );
164+ try (FileSystem fileSystem1 = FileSystems .newFileSystem (emptyZip , null );
165+ FileSystem fileSystem2 = FileSystems .newFileSystem (zipCopy , null )) {
166+ final Path dir1 = fileSystem1 .getPath ("" );
167+ final Path dir2 = fileSystem2 .getPath ("" );
168+ // WindowsPath, UnixPath, and ZipPath equals() methods always return false if the argument is not of the same instance as itself.
169+ assertTrue (PathUtils .directoryAndFileContentEquals (dir1 , dir2 ));
170+ }
171+ }
118172
119173 @ Test
120174 public void testDirectoryContentEquals () throws Exception {
0 commit comments