mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-31 06:15:48 +00:00
PasswordRepository: add custom FS factory for symlink capabilities (#1081)
Co-authored-by: Fabian Henneke <fabian@henneke.me>
This commit is contained in:
@@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Remember HTTPS password during a sync operation
|
- Remember HTTPS password during a sync operation
|
||||||
- Unable to use show/hide password option for password/passphrase after first attempt was wrong
|
- Unable to use show/hide password option for password/passphrase after first attempt was wrong
|
||||||
- TOTP values shown might some times be stale and considered invalid by sites
|
- TOTP values shown might some times be stale and considered invalid by sites
|
||||||
|
- Symlinks are no longer clobbered by the app (only available on Android 8 and above)
|
||||||
|
|
||||||
## [1.11.3] - 2020-08-27
|
## [1.11.3] - 2020-08-27
|
||||||
|
|
||||||
|
@@ -6,10 +6,14 @@ package com.zeapo.pwdstore.utils
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import com.zeapo.pwdstore.Application
|
import com.zeapo.pwdstore.Application
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileFilter
|
import java.io.FileFilter
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.LinkOption
|
||||||
import java.util.Comparator
|
import java.util.Comparator
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.Repository
|
import org.eclipse.jgit.lib.Repository
|
||||||
@@ -17,9 +21,37 @@ import org.eclipse.jgit.storage.file.FileRepositoryBuilder
|
|||||||
import org.eclipse.jgit.transport.RefSpec
|
import org.eclipse.jgit.transport.RefSpec
|
||||||
import org.eclipse.jgit.transport.RemoteConfig
|
import org.eclipse.jgit.transport.RemoteConfig
|
||||||
import org.eclipse.jgit.transport.URIish
|
import org.eclipse.jgit.transport.URIish
|
||||||
|
import org.eclipse.jgit.util.FS
|
||||||
|
import org.eclipse.jgit.util.FS_POSIX_Java6
|
||||||
|
|
||||||
open class PasswordRepository protected constructor() {
|
open class PasswordRepository protected constructor() {
|
||||||
|
|
||||||
|
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))
|
||||||
|
Files.delete(sourcePath)
|
||||||
|
Files.createSymbolicLink(sourcePath, File(target).toPath())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Java7FSFactory : FS.FSFactory() {
|
||||||
|
|
||||||
|
override fun detect(cygwinUsed: Boolean?): FS {
|
||||||
|
return FS_POSIX_Java6_with_optional_symlinks()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum class PasswordSortOrder(val comparator: Comparator<PasswordItem>) {
|
enum class PasswordSortOrder(val comparator: Comparator<PasswordItem>) {
|
||||||
|
|
||||||
FOLDER_FIRST(Comparator { p1: PasswordItem, p2: PasswordItem ->
|
FOLDER_FIRST(Comparator { p1: PasswordItem, p2: PasswordItem ->
|
||||||
@@ -75,6 +107,7 @@ open class PasswordRepository protected constructor() {
|
|||||||
val builder = FileRepositoryBuilder()
|
val builder = FileRepositoryBuilder()
|
||||||
try {
|
try {
|
||||||
repository = builder.setGitDir(localDir)
|
repository = builder.setGitDir(localDir)
|
||||||
|
.setFS(Java7FSFactory().detect(null))
|
||||||
.readEnvironment()
|
.readEnvironment()
|
||||||
.build()
|
.build()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Reference in New Issue
Block a user