-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
322 additions
and
142 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
34 changes: 34 additions & 0 deletions
34
src/main/java/org/cryptomator/cryptofs/attr/AttributeComponent.java
This file contains 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,34 @@ | ||
package org.cryptomator.cryptofs.attr; | ||
|
||
import dagger.BindsInstance; | ||
import dagger.Subcomponent; | ||
import org.cryptomator.cryptofs.common.CiphertextFileType; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.Optional; | ||
|
||
@AttributeScoped | ||
@Subcomponent(modules = {AttributeModule.class}) | ||
public interface AttributeComponent { | ||
|
||
Optional<BasicFileAttributes> attributes(); | ||
|
||
@Subcomponent.Builder | ||
interface Builder { | ||
|
||
@BindsInstance | ||
Builder type(Class<? extends BasicFileAttributes> type); | ||
|
||
@BindsInstance | ||
Builder ciphertextPath(Path ciphertextPath); | ||
|
||
@BindsInstance | ||
Builder ciphertextFileType(CiphertextFileType ciphertextFileType); | ||
|
||
@BindsInstance | ||
Builder ciphertextAttributes(BasicFileAttributes ciphertextAttributes); | ||
|
||
AttributeComponent build(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/org/cryptomator/cryptofs/attr/AttributeModule.java
This file contains 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,77 @@ | ||
package org.cryptomator.cryptofs.attr; | ||
|
||
import dagger.Binds; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import dagger.multibindings.ClassKey; | ||
import dagger.multibindings.IntoMap; | ||
import org.cryptomator.cryptofs.fh.OpenCryptoFile; | ||
import org.cryptomator.cryptofs.fh.OpenCryptoFiles; | ||
|
||
import javax.inject.Provider; | ||
import java.nio.file.Path; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.nio.file.attribute.DosFileAttributes; | ||
import java.nio.file.attribute.PosixFileAttributes; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@Module | ||
abstract class AttributeModule { | ||
|
||
@Provides | ||
@AttributeScoped | ||
public static Optional<OpenCryptoFile> provideOpenCryptoFile(OpenCryptoFiles openCryptoFiles, Path ciphertextPath) { | ||
return openCryptoFiles.get(ciphertextPath); | ||
} | ||
|
||
@Provides | ||
@AttributeScoped | ||
public static PosixFileAttributes providePosixFileAttributes(BasicFileAttributes ciphertextAttributes) { | ||
if (ciphertextAttributes instanceof PosixFileAttributes) { | ||
return (PosixFileAttributes) ciphertextAttributes; | ||
} else { | ||
throw new IllegalStateException("Attempted to inject instance of type " + ciphertextAttributes.getClass() + " but expected PosixFileAttributes."); | ||
} | ||
} | ||
|
||
@Provides | ||
@AttributeScoped | ||
public static DosFileAttributes provideDosFileAttributes(BasicFileAttributes ciphertextAttributes) { | ||
if (ciphertextAttributes instanceof DosFileAttributes) { | ||
return (DosFileAttributes) ciphertextAttributes; | ||
} else { | ||
throw new IllegalStateException("Attempted to inject instance of type " + ciphertextAttributes.getClass() + " but expected DosFileAttributes."); | ||
} | ||
} | ||
|
||
@Binds | ||
@IntoMap | ||
@ClassKey(BasicFileAttributes.class) | ||
@AttributeScoped | ||
public abstract BasicFileAttributes bindCryptoBasicFileAttributes(CryptoBasicFileAttributes view); | ||
|
||
@Binds | ||
@IntoMap | ||
@ClassKey(PosixFileAttributes.class) | ||
@AttributeScoped | ||
public abstract BasicFileAttributes bindCryptoPosixFileAttributes(CryptoPosixFileAttributes view); | ||
|
||
@Binds | ||
@IntoMap | ||
@ClassKey(DosFileAttributes.class) | ||
@AttributeScoped | ||
public abstract BasicFileAttributes bindCryptoDosFileAttributes(CryptoDosFileAttributes view); | ||
|
||
@Provides | ||
@AttributeScoped | ||
public static Optional<BasicFileAttributes> provideAttributes(Map<Class<?>, Provider<BasicFileAttributes>> providers, Class<? extends BasicFileAttributes> requestedType) { | ||
Provider<BasicFileAttributes> provider = providers.get(requestedType); | ||
if (provider == null) { | ||
return Optional.empty(); | ||
} else { | ||
return Optional.of(provider.get()); | ||
} | ||
} | ||
|
||
} |
This file contains 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/attr/AttributeScoped.java
This file contains 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.attr; | ||
|
||
import javax.inject.Scope; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
|
||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Scope | ||
@Documented | ||
@Retention(RUNTIME) | ||
@interface AttributeScoped { | ||
} |
This file contains 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 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
Oops, something went wrong.