From bf14c7dba7ea6712e3c10bf1fbf89281baa51040 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 1 Sep 2021 11:35:56 +0200 Subject: [PATCH 1/5] fix #111 --- .../java/org/cryptomator/cryptofs/LongFileNameProvider.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/cryptomator/cryptofs/LongFileNameProvider.java b/src/main/java/org/cryptomator/cryptofs/LongFileNameProvider.java index e427a2b0..1c69b258 100644 --- a/src/main/java/org/cryptomator/cryptofs/LongFileNameProvider.java +++ b/src/main/java/org/cryptomator/cryptofs/LongFileNameProvider.java @@ -116,11 +116,8 @@ public void persist() { private void persistInternal() throws IOException { Path longNameFile = c9sPath.resolve(INFLATED_FILE_NAME); Files.createDirectories(c9sPath); - try (WritableByteChannel ch = Files.newByteChannel(longNameFile, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW)) { + try (WritableByteChannel ch = Files.newByteChannel(longNameFile, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) { ch.write(UTF_8.encode(longName)); - } catch (FileAlreadyExistsException e) { - // no-op: if the file already exists, we assume its content to be what we want (or we found a SHA1 collision ;-)) - assert Arrays.equals(Files.readAllBytes(longNameFile), longName.getBytes(UTF_8)); } } } From 7d21c3e46fd880e35ccd2255b87fc39ba0ee8117 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 1 Sep 2021 11:36:18 +0200 Subject: [PATCH 2/5] add unit tests --- ...yptoFileSystemProviderIntegrationTest.java | 80 ++++++++++++++++--- 1 file changed, 67 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java index 549edc6f..a239625a 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java @@ -363,6 +363,38 @@ public void testRemoveOtherSymlink() throws IOException { @Test @Order(9) + @DisplayName("ln -s foo '/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet'") + public void testCreateSymlinkWithLongName() throws IOException { + Path target = fs1.getPath("/foo"); + Assumptions.assumeTrue(Files.isRegularFile(target)); + Path longNameLink = fs1.getPath("/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet"); + Files.createSymbolicLink(longNameLink, target); + MatcherAssert.assertThat(MoreFiles.listFiles(fs1.getPath("/")), Matchers.hasItem(longNameLink)); + Assertions.assertTrue(Files.exists(longNameLink)); + } + + @Test + @Order(10) + @DisplayName("mv '/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet' '/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat") + public void testMoveSymlinkWithLongNameToAnotherLongName() throws IOException { + Path longNameSource = fs1.getPath("/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet"); + Assumptions.assumeTrue(Files.isSymbolicLink(longNameSource)); + Path longNameTarget = longNameSource.resolveSibling("/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat"); + Files.move(longNameSource, longNameTarget); + Assertions.assertTrue(Files.exists(longNameTarget)); + Assertions.assertTrue(Files.notExists(longNameSource)); + } + + @Test + @Order(11) + @DisplayName("rm -r '/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat'") + public void testRemoveSymlinkWithLongName() throws IOException { + Path longNamePath = fs1.getPath("/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat"); + Files.delete(longNamePath); + Assertions.assertTrue(Files.notExists(longNamePath)); + } + @Test + @Order(12) @DisplayName("mkdir '/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet'") public void testCreateDirWithLongName() throws IOException { Path longNamePath = fs1.getPath("/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet"); @@ -372,16 +404,27 @@ public void testCreateDirWithLongName() throws IOException { } @Test - @Order(10) - @DisplayName("rm -r '/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet'") + @Order(13) + @DisplayName("mv '/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet' '/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat") + public void testMoveDirWithLongNameToAnotherLongName() throws IOException { + Path longNameSource = fs1.getPath("/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet"); + Path longNameTarget = longNameSource.resolveSibling("/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat"); + Files.move(longNameSource, longNameTarget); + Assertions.assertTrue(Files.exists(longNameTarget)); + Assertions.assertTrue(Files.notExists(longNameSource)); + } + + @Test + @Order(14) + @DisplayName("rm -r '/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat'") public void testRemoveDirWithLongName() throws IOException { - Path longNamePath = fs1.getPath("/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet"); + Path longNamePath = fs1.getPath("/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat"); Files.delete(longNamePath); Assertions.assertTrue(Files.notExists(longNamePath)); } @Test - @Order(11) + @Order(15) @DisplayName("touch '/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet'") public void testCreateFileWithLongName() throws IOException { Path longNamePath = fs1.getPath("/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet"); @@ -391,16 +434,27 @@ public void testCreateFileWithLongName() throws IOException { } @Test - @Order(12) - @DisplayName("rm '/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet'") + @Order(16) + @DisplayName("mv '/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet' '/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat") + public void testMoveFileWithLongNameToAnotherLongName() throws IOException { + Path longNameSource = fs1.getPath("/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet"); + Path longNameTarget = longNameSource.resolveSibling("/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat"); + Files.move(longNameSource, longNameTarget); + Assertions.assertTrue(Files.exists(longNameTarget)); + Assertions.assertTrue(Files.notExists(longNameSource)); + } + + @Test + @Order(17) + @DisplayName("rm -r '/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat'") public void testRemoveFileWithLongName() throws IOException { - Path longNamePath = fs1.getPath("/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen Internet"); + Path longNamePath = fs1.getPath("/Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat Talafan Anargaa Wassar Wabsaatangaraffal Bas Bahn Maatwagan Antarnat"); Files.delete(longNamePath); Assertions.assertTrue(Files.notExists(longNamePath)); } @Test - @Order(13) + @Order(18) @DisplayName("cp fs1:/foo fs2:/bar") public void testCopyFileAcrossFilesystem() throws IOException { Path file1 = fs1.getPath("/foo"); @@ -414,7 +468,7 @@ public void testCopyFileAcrossFilesystem() throws IOException { } @Test - @Order(14) + @Order(19) @DisplayName("echo 'goodbye world' > /foo") public void testWriteToFile() throws IOException { Path file1 = fs1.getPath("/foo"); @@ -423,7 +477,7 @@ public void testWriteToFile() throws IOException { } @Test - @Order(15) + @Order(20) @DisplayName("cp -f fs1:/foo fs2:/bar") public void testCopyFileAcrossFilesystemReplaceExisting() throws IOException { Path file1 = fs1.getPath("/foo"); @@ -437,7 +491,7 @@ public void testCopyFileAcrossFilesystemReplaceExisting() throws IOException { } @Test - @Order(16) + @Order(21) @DisplayName("readattr /attributes.txt") public void testLazinessOfFileAttributeViews() throws IOException { Path file = fs1.getPath("/attributes.txt"); @@ -462,7 +516,7 @@ public void testLazinessOfFileAttributeViews() throws IOException { } @Test - @Order(17) + @Order(22) @DisplayName("ln -s /linked/targetY /links/linkX") public void testSymbolicLinks() throws IOException { Path linksDir = fs1.getPath("/links"); @@ -501,7 +555,7 @@ public void testSymbolicLinks() throws IOException { } @Test - @Order(18) + @Order(22) @DisplayName("mv -f fs1:/foo fs2:/baz") public void testMoveFileFromOneCryptoFileSystemToAnother() throws IOException { Path file1 = fs1.getPath("/foo"); From f8079199c313942cf83efe134c16aca629a9336a Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 2 Sep 2021 10:20:28 +0200 Subject: [PATCH 3/5] simplify code --- .../java/org/cryptomator/cryptofs/LongFileNameProvider.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/cryptomator/cryptofs/LongFileNameProvider.java b/src/main/java/org/cryptomator/cryptofs/LongFileNameProvider.java index 1c69b258..df197db8 100644 --- a/src/main/java/org/cryptomator/cryptofs/LongFileNameProvider.java +++ b/src/main/java/org/cryptomator/cryptofs/LongFileNameProvider.java @@ -116,9 +116,7 @@ public void persist() { private void persistInternal() throws IOException { Path longNameFile = c9sPath.resolve(INFLATED_FILE_NAME); Files.createDirectories(c9sPath); - try (WritableByteChannel ch = Files.newByteChannel(longNameFile, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) { - ch.write(UTF_8.encode(longName)); - } + Files.write(longNameFile,UTF_8.encode(longName).array()); //WRITE, CREATE, TRUNCATE_EXISTING } } From 1be02c3bc598565ed19b7ab4e47fddce62d73298 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 2 Sep 2021 10:31:00 +0200 Subject: [PATCH 4/5] prepare 2.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 62515786..a1702bb0 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.cryptomator cryptofs - 2.0.0 + 2.0.1 Cryptomator Crypto Filesystem This library provides the Java filesystem provider used by Cryptomator. https://github.com/cryptomator/cryptofs From d2acd43df8ca5a95e652fc5f49812de61df1e103 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 2 Sep 2021 11:03:06 +0200 Subject: [PATCH 5/5] update to cryptolib 2.0.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 99f7c2f5..17414954 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 16 - 2.0.1 + 2.0.2 3.18.1 2.37 30.1.1-jre