Skip to content

Commit 6a4ed6f

Browse files
authored
Feature: Add timestamp to file system events (#291)
1 parent 2932957 commit 6a4ed6f

File tree

6 files changed

+66
-9
lines changed

6 files changed

+66
-9
lines changed
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
package org.cryptomator.cryptofs.event;
22

33
import java.nio.file.Path;
4+
import java.time.Instant;
45

56
/**
67
* Emitted, if a dir.c9r file is empty or exceeds 1000 Bytes.
78
*
9+
* @param timestamp timestamp of event appearance
810
* @param ciphertextPath path to the broken dir.c9r file
911
*/
10-
public record BrokenDirFileEvent(Path ciphertextPath) implements FilesystemEvent {
12+
public record BrokenDirFileEvent(Instant timestamp, Path ciphertextPath) implements FilesystemEvent {
1113

14+
public BrokenDirFileEvent(Path ciphertextPath) {
15+
this(Instant.now(), ciphertextPath);
16+
}
17+
18+
@Override
19+
public Instant getTimestamp() {
20+
return timestamp;
21+
}
1222
}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
package org.cryptomator.cryptofs.event;
22

33
import java.nio.file.Path;
4+
import java.time.Instant;
45

56
/**
67
* Emitted, if a path within the cryptographic filesystem is accessed, but the directory representing it is missing identification files.
78
*
9+
* @param timestamp timestamp of event appearance
810
* @param cleartextPath path within the cryptographic filesystem
911
* @param ciphertextPath path of the incomplete, encrypted directory
10-
*
1112
* @see org.cryptomator.cryptofs.health.type.UnknownType
1213
*/
13-
public record BrokenFileNodeEvent(Path cleartextPath, Path ciphertextPath) implements FilesystemEvent {
14+
public record BrokenFileNodeEvent(Instant timestamp, Path cleartextPath, Path ciphertextPath) implements FilesystemEvent {
15+
16+
public BrokenFileNodeEvent(Path cleartextPath, Path ciphertextPath) {
17+
this(Instant.now(), cleartextPath, ciphertextPath);
18+
}
1419

20+
@Override
21+
public Instant getTimestamp() {
22+
return timestamp;
23+
}
1524
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
package org.cryptomator.cryptofs.event;
22

33
import java.nio.file.Path;
4+
import java.time.Instant;
45

56
/**
67
* Emitted, if the conflict resolution inside an encrypted directory failed
78
*
9+
* @param timestamp timestamp of event appearance
810
* @param canonicalCleartextPath path of the canonical file within the cryptographic filesystem
911
* @param conflictingCiphertextPath path of the encrypted, conflicting file
1012
* @param reason exception, why the resolution failed
1113
*/
12-
public record ConflictResolutionFailedEvent(Path canonicalCleartextPath, Path conflictingCiphertextPath, Exception reason) implements FilesystemEvent {
14+
public record ConflictResolutionFailedEvent(Instant timestamp, Path canonicalCleartextPath, Path conflictingCiphertextPath, Exception reason) implements FilesystemEvent {
1315

16+
public ConflictResolutionFailedEvent(Path canonicalCleartextPath, Path conflictingCiphertextPath, Exception reason) {
17+
this(Instant.now(), canonicalCleartextPath, conflictingCiphertextPath, reason);
18+
}
19+
20+
@Override
21+
public Instant getTimestamp() {
22+
return timestamp;
23+
}
1424
}

src/main/java/org/cryptomator/cryptofs/event/ConflictResolvedEvent.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.cryptomator.cryptofs.event;
22

33
import java.nio.file.Path;
4+
import java.time.Instant;
45

56
/**
67
* Emitted, if a conflict inside an encrypted directory was resolved.
@@ -10,11 +11,20 @@
1011
* The file <i>with the suffix</i> is called <b>conflicting</b>
1112
* On successful conflict resolution the conflicting file is renamed to the <b>resolved</b> file
1213
*
14+
* @param timestamp timestamp of event appearance
1315
* @param canonicalCleartextPath path of the canonical file within the cryptographic filesystem
1416
* @param conflictingCiphertextPath path of the encrypted, conflicting file
1517
* @param resolvedCleartextPath path of the resolved file within the cryptographic filesystem
1618
* @param resolvedCiphertextPath path of the resolved, encrypted file
1719
*/
18-
public record ConflictResolvedEvent(Path canonicalCleartextPath, Path conflictingCiphertextPath, Path resolvedCleartextPath, Path resolvedCiphertextPath) implements FilesystemEvent {
20+
public record ConflictResolvedEvent(Instant timestamp, Path canonicalCleartextPath, Path conflictingCiphertextPath, Path resolvedCleartextPath, Path resolvedCiphertextPath) implements FilesystemEvent {
1921

22+
public ConflictResolvedEvent(Path canonicalCleartextPath, Path conflictingCiphertextPath, Path resolvedCleartextPath, Path resolvedCiphertextPath) {
23+
this(Instant.now(), canonicalCleartextPath, conflictingCiphertextPath, resolvedCleartextPath, resolvedCiphertextPath);
24+
}
25+
26+
@Override
27+
public Instant getTimestamp() {
28+
return timestamp;
29+
}
2030
}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
package org.cryptomator.cryptofs.event;
22

33
import java.nio.file.Path;
4+
import java.time.Instant;
45

56
/**
67
* Emitted, if a decryption operation fails.
78
*
9+
* @param timestamp timestamp of event appearance
810
* @param ciphertextPath path to the encrypted resource
911
* @param e thrown exception
1012
*/
11-
public record DecryptionFailedEvent(Path ciphertextPath, Exception e) implements FilesystemEvent {
13+
public record DecryptionFailedEvent(Instant timestamp, Path ciphertextPath, Exception e) implements FilesystemEvent {
14+
15+
public DecryptionFailedEvent(Path ciphertextPath, Exception e) {
16+
this(Instant.now(), ciphertextPath, e);
17+
}
18+
19+
@Override
20+
public Instant getTimestamp() {
21+
return timestamp;
22+
}
1223
}

src/main/java/org/cryptomator/cryptofs/event/FilesystemEvent.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cryptomator.cryptofs.event;
22

3+
import java.time.Instant;
34
import java.util.function.Consumer;
45

56
/**
@@ -11,11 +12,11 @@
1112
* {@code
1213
* FilesystemEvent fse;
1314
* switch (fse) {
14-
* case DecryptionFailedEvent e -> //do stuff
1515
* case ConflictResolvedEvent e -> //do other stuff
16-
* //other cases
16+
* case DecryptionFailedEvent(Instant timestamp, Path ciphertext, Exception ex) -> //do stuff
17+
* //... other cases
1718
* }
18-
* if( fse instanceof DecryptionFailedEvent dfe) {
19+
* if( fse instanceof DecryptionFailedEvent(Instant timestamp, Path ciphertext, Exception ex) {
1920
* //do more stuff
2021
* }
2122
* }.
@@ -24,4 +25,10 @@
2425
*/
2526
public sealed interface FilesystemEvent permits BrokenDirFileEvent, BrokenFileNodeEvent, ConflictResolutionFailedEvent, ConflictResolvedEvent, DecryptionFailedEvent {
2627

28+
/**
29+
* Gets the timestamp when the event occurred.
30+
*
31+
* @return the event timestamp as an {@link Instant}
32+
*/
33+
Instant getTimestamp();
2734
}

0 commit comments

Comments
 (0)