- 
        Couldn't load subscription status. 
- Fork 35
Feature: Notification API for Filesystem events #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            21 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      3695e62
              
                impl draft based on FileSystemProperties
              
              
                infeo d6ebcf4
              
                Merge branch 'develop' into feature/fs-notify
              
              
                infeo e44c2e4
              
                simplified API
              
              
                infeo fecb0a2
              
                use records
              
              
                infeo 1689c58
              
                add conflictResolved event
              
              
                infeo 7a564fb
              
                add conflict failed event
              
              
                infeo c942596
              
                clean up
              
              
                infeo e94ebc2
              
                use sealed interface instead of type enum
              
              
                infeo 5e552d1
              
                doc doc doc
              
              
                infeo 311b86c
              
                clean up
              
              
                infeo 53d5cd9
              
                remove unused parameter in decryption failed event
              
              
                infeo ea091f0
              
                ensure eventConsumer is never null
              
              
                infeo 19117bc
              
                ensure, that on any RuntimeException during event consumption the fil…
              
              
                infeo 2cd07fa
              
                standardize parameter naming for conflict resolution events
              
              
                infeo 60a0fc8
              
                fix wrong path resolution
              
              
                infeo 30ee882
              
                adjust doc
              
              
                infeo 3691c6b
              
                rename eventConsumer variables in CryptoFileSystemProperties
              
              
                infeo fb5b302
              
                rename method
              
              
                infeo 1ff1f1d
              
                Merge branch 'develop' into feature/fs-notify
              
              
                infeo 3df3c4e
              
                increase test coverage
              
              
                infeo 9fddb8b
              
                align key name for event consumer entry in properties to public build…
              
              
                infeo File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            14 changes: 14 additions & 0 deletions
          
          14 
        
  src/main/java/org/cryptomator/cryptofs/event/ConflictResolutionFailedEvent.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.cryptomator.cryptofs.event; | ||
|  | ||
| import java.nio.file.Path; | ||
|  | ||
| /** | ||
| * Emitted, if the conflict resolution inside an encrypted directory failed | ||
| * | ||
| * @param canonicalCleartextPath path of the canonical file within the cryptographic filesystem | ||
| * @param conflictingCiphertextPath path of the encrypted, conflicting file | ||
| * @param reason exception, why the resolution failed | ||
| */ | ||
| public record ConflictResolutionFailedEvent(Path canonicalCleartextPath, Path conflictingCiphertextPath, Exception reason) implements FilesystemEvent { | ||
|  | ||
| } | 
        
          
          
            20 changes: 20 additions & 0 deletions
          
          20 
        
  src/main/java/org/cryptomator/cryptofs/event/ConflictResolvedEvent.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.cryptomator.cryptofs.event; | ||
|  | ||
| import java.nio.file.Path; | ||
|  | ||
| /** | ||
| * Emitted, if a conflict inside an encrypted directory was resolved. | ||
| * <p> | ||
| * A conflict exists, if two encrypted files with the same base64url string exist, but the second file has an arbitrary suffix before the file extension. | ||
| * The file <i>without</i> the suffix is called <b>canonical</b>. | ||
| * The file <i>with the suffix</i> is called <b>conflicting</b> | ||
| * On successful conflict resolution the conflicting file is renamed to the <b>resolved</b> file | ||
| * | ||
| * @param canonicalCleartextPath path of the canonical file within the cryptographic filesystem | ||
| * @param conflictingCiphertextPath path of the encrypted, conflicting file | ||
| * @param resolvedCleartextPath path of the resolved file within the cryptographic filesystem | ||
| * @param resolvedCiphertextPath path of the resolved, encrypted file | ||
| */ | ||
| public record ConflictResolvedEvent(Path canonicalCleartextPath, Path conflictingCiphertextPath, Path resolvedCleartextPath, Path resolvedCiphertextPath) implements FilesystemEvent { | ||
|  | ||
| } | 
        
          
          
            15 changes: 15 additions & 0 deletions
          
          15 
        
  src/main/java/org/cryptomator/cryptofs/event/DecryptionFailedEvent.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.cryptomator.cryptofs.event; | ||
|  | ||
| import org.cryptomator.cryptolib.api.AuthenticationFailedException; | ||
|  | ||
| import java.nio.file.Path; | ||
|  | ||
| /** | ||
| * Emitted, if a decryption operation fails. | ||
| * | ||
| * @param ciphertextPath path to the encrypted resource | ||
| * @param e thrown exception | ||
| */ | ||
| public record DecryptionFailedEvent(Path ciphertextPath, AuthenticationFailedException e) implements FilesystemEvent { | ||
|  | ||
| } | ||
        
          
          
            27 changes: 27 additions & 0 deletions
          
          27 
        
  src/main/java/org/cryptomator/cryptofs/event/FilesystemEvent.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package org.cryptomator.cryptofs.event; | ||
|  | ||
| import java.util.function.Consumer; | ||
|  | ||
| /** | ||
| * Common interface for all filesystem events. | ||
| * <p> | ||
| * Events are emitted via the notification method set in the properties during filesystem creation, see {@link org.cryptomator.cryptofs.CryptoFileSystemProperties.Builder#withFilesystemEventConsumer(Consumer)}. | ||
| * <p> | ||
| * To get a specific event type, use the enhanced switch pattern or typecasting in if-instance of, e.g. | ||
| * {@code | ||
| * FilesystemEvent fse; | ||
| * switch (fse) { | ||
| * case DecryptionFailedEvent e -> //do stuff | ||
| * case ConflictResolvedEvent e -> //do other stuff | ||
| * //other cases | ||
| * } | ||
| * if( fse instanceof DecryptionFailedEvent dfe) { | ||
| * //do more stuff | ||
| * } | ||
| * }. | ||
| * | ||
| * @apiNote Events might have occured a long time ago in a galaxy far, far away... therefore, any feedback method is non-blocking and might fail due to changes in the filesystem. | ||
| */ | ||
| public sealed interface FilesystemEvent permits ConflictResolutionFailedEvent, ConflictResolvedEvent, DecryptionFailedEvent { | ||
|  | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            35 changes: 35 additions & 0 deletions
          
          35 
        
  src/test/java/org/cryptomator/cryptofs/CryptoFileSystemModuleTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package org.cryptomator.cryptofs; | ||
|  | ||
| import org.cryptomator.cryptofs.event.ConflictResolutionFailedEvent; | ||
| import org.cryptomator.cryptofs.event.FilesystemEvent; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
|  | ||
| import java.nio.file.Path; | ||
| import java.util.function.Consumer; | ||
|  | ||
| import static org.mockito.Mockito.doThrow; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|  | ||
| public class CryptoFileSystemModuleTest { | ||
|  | ||
| CryptoFileSystemModule inTest = new CryptoFileSystemModule(); | ||
|  | ||
| @Test | ||
| void testEventConsumerIsDecorated() { | ||
| var p = Mockito.mock(Path.class); | ||
| var event = new ConflictResolutionFailedEvent(p, p, new RuntimeException()); | ||
| var eventConsumer = (Consumer<FilesystemEvent>) mock(Consumer.class); | ||
| doThrow(new RuntimeException("fail")).when(eventConsumer).accept(event); | ||
| var props = mock(CryptoFileSystemProperties.class); | ||
| when(props.filesystemEventConsumer()).thenReturn(eventConsumer); | ||
|  | ||
| var decoratedConsumer = inTest.provideFilesystemEventConsumer(props); | ||
| Assertions.assertDoesNotThrow(() -> decoratedConsumer.accept(event)); | ||
| verify(eventConsumer).accept(event); | ||
| } | ||
|  | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.