From eef809760c7359a34b414af45165b157813e78af Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 13 Sep 2020 15:24:15 +0530 Subject: PasswordRepository: properly gate symlink feature (#1098) Signed-off-by: Harsh Shandilya --- .../java/com/zeapo/pwdstore/utils/PasswordRepository.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt index 443e7398..f1655b3b 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt @@ -29,17 +29,15 @@ import org.eclipse.jgit.util.FS_POSIX_Java6 open class PasswordRepository protected constructor() { + @RequiresApi(Build.VERSION_CODES.O) private class FS_POSIX_Java6_with_optional_symlinks : FS_POSIX_Java6() { override fun supportsSymlinks() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - @RequiresApi(Build.VERSION_CODES.O) override fun isSymLink(file: File) = Files.isSymbolicLink(file.toPath()) - @RequiresApi(Build.VERSION_CODES.O) override fun readSymLink(file: File) = Files.readSymbolicLink(file.toPath()).toString() - @RequiresApi(Build.VERSION_CODES.O) override fun createSymLink(source: File, target: String) { val sourcePath = source.toPath() if (Files.exists(sourcePath, LinkOption.NOFOLLOW_LINKS)) @@ -48,6 +46,7 @@ open class PasswordRepository protected constructor() { } } + @RequiresApi(Build.VERSION_CODES.O) private class Java7FSFactory : FS.FSFactory() { override fun detect(cygwinUsed: Boolean?): FS { @@ -109,10 +108,13 @@ open class PasswordRepository protected constructor() { if (repository == null && localDir != null) { val builder = FileRepositoryBuilder() repository = runCatching { - builder.setGitDir(localDir) - .setFS(Java7FSFactory().detect(null)) - .readEnvironment() - .build() + builder.run { + gitDir = localDir + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + fs = Java7FSFactory().detect(null) + } + readEnvironment() + }.build() }.getOrElse { e -> e.printStackTrace() null -- cgit v1.2.3