Skip to content

Commit 2c8b993

Browse files
Partially reverting 97f473b:
Only write name.c9s files once, not during every access.
1 parent 75905f2 commit 2c8b993

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/java/org/cryptomator/cryptofs/LongFileNameProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
import java.nio.ByteBuffer;
2222
import java.nio.channels.SeekableByteChannel;
2323
import java.nio.channels.WritableByteChannel;
24+
import java.nio.file.FileAlreadyExistsException;
2425
import java.nio.file.Files;
2526
import java.nio.file.Path;
2627
import java.nio.file.StandardOpenOption;
2728
import java.time.Duration;
29+
import java.util.Arrays;
2830
import java.util.concurrent.ExecutionException;
2931

3032
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -111,8 +113,11 @@ public void persist() {
111113
private void persistInternal() throws IOException {
112114
Path longNameFile = c9sPath.resolve(INFLATED_FILE_NAME);
113115
Files.createDirectories(c9sPath);
114-
try (WritableByteChannel ch = Files.newByteChannel(longNameFile, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
116+
try (WritableByteChannel ch = Files.newByteChannel(longNameFile, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW)) {
115117
ch.write(UTF_8.encode(longName));
118+
} catch (FileAlreadyExistsException e) {
119+
// no-op: if the file already exists, we assume its content to be what we want (or we found a SHA1 collision ;-))
120+
assert Arrays.equals(Files.readAllBytes(longNameFile), longName.getBytes(UTF_8));
116121
}
117122
}
118123
}

0 commit comments

Comments
 (0)