PasswordRepository: properly gate symlink feature (#1098)

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya
2020-09-13 15:24:15 +05:30
committed by GitHub
parent f2647dfbe6
commit eef809760c

View File

@@ -29,17 +29,15 @@ import org.eclipse.jgit.util.FS_POSIX_Java6
open class PasswordRepository protected constructor() { open class PasswordRepository protected constructor() {
@RequiresApi(Build.VERSION_CODES.O)
private class FS_POSIX_Java6_with_optional_symlinks : FS_POSIX_Java6() { private class FS_POSIX_Java6_with_optional_symlinks : FS_POSIX_Java6() {
override fun supportsSymlinks() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O 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()) override fun isSymLink(file: File) = Files.isSymbolicLink(file.toPath())
@RequiresApi(Build.VERSION_CODES.O)
override fun readSymLink(file: File) = Files.readSymbolicLink(file.toPath()).toString() override fun readSymLink(file: File) = Files.readSymbolicLink(file.toPath()).toString()
@RequiresApi(Build.VERSION_CODES.O)
override fun createSymLink(source: File, target: String) { override fun createSymLink(source: File, target: String) {
val sourcePath = source.toPath() val sourcePath = source.toPath()
if (Files.exists(sourcePath, LinkOption.NOFOLLOW_LINKS)) 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() { private class Java7FSFactory : FS.FSFactory() {
override fun detect(cygwinUsed: Boolean?): FS { override fun detect(cygwinUsed: Boolean?): FS {
@@ -109,10 +108,13 @@ open class PasswordRepository protected constructor() {
if (repository == null && localDir != null) { if (repository == null && localDir != null) {
val builder = FileRepositoryBuilder() val builder = FileRepositoryBuilder()
repository = runCatching { repository = runCatching {
builder.setGitDir(localDir) builder.run {
.setFS(Java7FSFactory().detect(null)) gitDir = localDir
.readEnvironment() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
.build() fs = Java7FSFactory().detect(null)
}
readEnvironment()
}.build()
}.getOrElse { e -> }.getOrElse { e ->
e.printStackTrace() e.printStackTrace()
null null