mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-30 13:57:47 +00:00
Remove Apache Commons dependencies (#840)
Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
committed by
GitHub
parent
7569d40270
commit
0050deb501
@@ -94,8 +94,6 @@ dependencies {
|
||||
implementation deps.kotlin.coroutines.android
|
||||
implementation deps.kotlin.coroutines.core
|
||||
|
||||
implementation deps.third_party.commons_io
|
||||
implementation deps.third_party.commons_codec
|
||||
implementation deps.third_party.fastscroll
|
||||
implementation(deps.third_party.jgit) {
|
||||
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
|
||||
|
@@ -55,6 +55,7 @@ import com.zeapo.pwdstore.git.GitOperationActivity
|
||||
import com.zeapo.pwdstore.git.GitServerConfigActivity
|
||||
import com.zeapo.pwdstore.git.config.ConnectionMode
|
||||
import com.zeapo.pwdstore.ui.dialogs.FolderCreationDialogFragment
|
||||
import com.zeapo.pwdstore.utils.FileUtils
|
||||
import com.zeapo.pwdstore.utils.PasswordItem
|
||||
import com.zeapo.pwdstore.utils.PasswordRepository
|
||||
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.closeRepository
|
||||
@@ -65,8 +66,6 @@ import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getRepositoryDirect
|
||||
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.initialize
|
||||
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.isInitialized
|
||||
import com.zeapo.pwdstore.utils.PasswordRepository.PasswordSortOrder.Companion.getSortOrder
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.apache.commons.io.FilenameUtils
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.api.errors.GitAPIException
|
||||
import org.eclipse.jgit.revwalk.RevCommit
|
||||
@@ -577,7 +576,7 @@ class PasswordStore : AppCompatActivity() {
|
||||
.setMessage(resources.getString(R.string.delete_dialog_text, item.longName))
|
||||
.setPositiveButton(resources.getString(R.string.dialog_yes)) { _, _ ->
|
||||
val filesToDelete = if (item.file.isDirectory) {
|
||||
FileUtils.listFiles(item.file, null, true)
|
||||
FileUtils.listFiles(item.file, true)
|
||||
} else {
|
||||
listOf(item.file)
|
||||
}
|
||||
@@ -668,7 +667,7 @@ class PasswordStore : AppCompatActivity() {
|
||||
if (dir != null &&
|
||||
dir.exists() &&
|
||||
dir.isDirectory &&
|
||||
!FileUtils.listFiles(dir, null, true).isEmpty() &&
|
||||
!FileUtils.listFiles(dir, true).isEmpty() &&
|
||||
getPasswords(dir, getRepositoryDirectory(this), sortOrder).isNotEmpty()) {
|
||||
closeRepository()
|
||||
checkLocalRepository()
|
||||
@@ -703,7 +702,7 @@ class PasswordStore : AppCompatActivity() {
|
||||
continue
|
||||
}
|
||||
val destinationFile = File(target.absolutePath + "/" + source.name)
|
||||
val basename = FilenameUtils.getBaseName(source.absolutePath)
|
||||
val basename = FileUtils.getBaseName(source.absolutePath)
|
||||
val sourceLongName = getLongName(requireNotNull(source.parent), repositoryPath, basename)
|
||||
val destinationLongName = getLongName(target.absolutePath, repositoryPath, basename)
|
||||
if (destinationFile.exists()) {
|
||||
@@ -739,7 +738,7 @@ class PasswordStore : AppCompatActivity() {
|
||||
// Recursively list all files (not directories) below `source`, then
|
||||
// obtain the corresponding target file by resolving the relative path
|
||||
// starting at the destination folder.
|
||||
val sourceFiles = FileUtils.listFiles(source, null, true)
|
||||
val sourceFiles = FileUtils.listFiles(source, true)
|
||||
sourceFiles.associateWith { destinationFile.resolve(it.relativeTo(source)) }
|
||||
} else {
|
||||
mapOf(source to destinationFile)
|
||||
|
@@ -36,6 +36,7 @@ import androidx.preference.PreferenceManager
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import com.github.ajalt.timberkt.Timber.tag
|
||||
import com.github.ajalt.timberkt.d
|
||||
import com.github.ajalt.timberkt.w
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.zeapo.pwdstore.autofill.AutofillPreferenceActivity
|
||||
@@ -52,7 +53,6 @@ import com.zeapo.pwdstore.utils.PasswordRepository
|
||||
import com.zeapo.pwdstore.utils.autofillManager
|
||||
import com.zeapo.pwdstore.utils.getEncryptedPrefs
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpUtils
|
||||
import org.apache.commons.io.FileUtils
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.time.LocalDateTime
|
||||
@@ -227,7 +227,7 @@ class UserPreference : AppCompatActivity() {
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.dialog_delete) { dialogInterface, _ ->
|
||||
try {
|
||||
FileUtils.cleanDirectory(PasswordRepository.getRepositoryDirectory(callingActivity.applicationContext))
|
||||
PasswordRepository.getRepositoryDirectory(callingActivity.applicationContext).deleteRecursively()
|
||||
PasswordRepository.closeRepository()
|
||||
} catch (ignored: Exception) {
|
||||
// TODO Handle the different cases of exceptions
|
||||
@@ -357,8 +357,8 @@ class UserPreference : AppCompatActivity() {
|
||||
prefIsCustomDict?.onPreferenceChangeListener = ChangeListener { _, newValue ->
|
||||
if (!(newValue as Boolean)) {
|
||||
val customDictFile = File(context.filesDir, XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE)
|
||||
if (customDictFile.exists()) {
|
||||
FileUtils.deleteQuietly(customDictFile)
|
||||
if (customDictFile.exists() && !customDictFile.delete()) {
|
||||
w { "Failed to delete custom XkPassword dictionary: $customDictFile" }
|
||||
}
|
||||
prefCustomDictPicker?.setSummary(R.string.xkpwgen_pref_custom_dict_picker_summary)
|
||||
}
|
||||
@@ -706,9 +706,11 @@ class UserPreference : AppCompatActivity() {
|
||||
val customDictPref = prefsFragment.findPreference<Preference>("pref_key_custom_dict")
|
||||
setCustomDictSummary(customDictPref, uri)
|
||||
// copy user selected file to internal storage
|
||||
val inputStream = this.contentResolver.openInputStream(uri)
|
||||
val customDictFile = File(this.filesDir.toString(), XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE)
|
||||
FileUtils.copyInputStreamToFile(inputStream, customDictFile)
|
||||
val inputStream = contentResolver.openInputStream(uri)
|
||||
val customDictFile = File(filesDir.toString(), XkpwdDictionary.XKPWD_CUSTOM_DICT_FILE).outputStream()
|
||||
inputStream?.copyTo(customDictFile, 1024)
|
||||
inputStream?.close()
|
||||
customDictFile.close()
|
||||
|
||||
setResult(Activity.RESULT_OK)
|
||||
}
|
||||
|
@@ -39,7 +39,6 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.openintents.openpgp.IOpenPgpService2
|
||||
import org.openintents.openpgp.OpenPgpError
|
||||
import java.io.ByteArrayOutputStream
|
||||
@@ -497,7 +496,7 @@ class AutofillService : AccessibilityService(), CoroutineScope by CoroutineScope
|
||||
var inputStream: InputStream? = null
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
inputStream = FileUtils.openInputStream(items[lastWhichItem])
|
||||
inputStream = items[lastWhichItem].inputStream()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
cancel("", e)
|
||||
|
@@ -43,6 +43,7 @@ import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences
|
||||
import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure
|
||||
import com.zeapo.pwdstore.ui.dialogs.PasswordGeneratorDialogFragment
|
||||
import com.zeapo.pwdstore.ui.dialogs.XkPasswordGeneratorDialogFragment
|
||||
import com.zeapo.pwdstore.utils.FileUtils
|
||||
import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_category_decrypt
|
||||
import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_file
|
||||
import kotlinx.android.synthetic.main.decrypt_layout.crypto_password_last_changed
|
||||
@@ -69,8 +70,6 @@ import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.RESULT_CODE_USER_INTERA
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.RESULT_ERROR
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpApi.Companion.RESULT_INTENT
|
||||
import me.msfjarvis.openpgpktx.util.OpenPgpServiceConnection
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.apache.commons.io.FilenameUtils
|
||||
import org.openintents.openpgp.IOpenPgpService2
|
||||
import org.openintents.openpgp.OpenPgpError
|
||||
import java.io.ByteArrayInputStream
|
||||
@@ -352,7 +351,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
val data = receivedIntent ?: Intent()
|
||||
data.action = ACTION_DECRYPT_VERIFY
|
||||
|
||||
val iStream = FileUtils.openInputStream(File(fullPath))
|
||||
val iStream = File(fullPath).inputStream()
|
||||
val oStream = ByteArrayOutputStream()
|
||||
|
||||
lifecycleScope.launch(IO) {
|
||||
@@ -478,7 +477,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
try {
|
||||
// TODO This might fail, we should check that the write is successful
|
||||
val file = File(path)
|
||||
val outputStream = FileUtils.openOutputStream(file)
|
||||
val outputStream = file.outputStream()
|
||||
outputStream.write(oStream.toByteArray())
|
||||
outputStream.close()
|
||||
|
||||
@@ -772,7 +771,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
* Gets the name of the password (excluding .gpg)
|
||||
*/
|
||||
fun getName(fullPath: String): String {
|
||||
return FilenameUtils.getBaseName(fullPath)
|
||||
return FileUtils.getBaseName(fullPath)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,7 +16,7 @@ import androidx.core.content.getSystemService
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.zeapo.pwdstore.R
|
||||
import org.apache.commons.io.FileUtils
|
||||
import com.zeapo.pwdstore.utils.FileUtils
|
||||
import java.io.File
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
@@ -61,7 +61,7 @@ class ShowSshKeyFragment : DialogFragment() {
|
||||
private fun readKeyFromFile() {
|
||||
val file = File(requireActivity().filesDir.toString() + "/.ssh_key.pub")
|
||||
try {
|
||||
publicKey.text = FileUtils.readFileToString(file, StandardCharsets.UTF_8)
|
||||
publicKey.text = file.readText()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
47
app/src/main/java/com/zeapo/pwdstore/utils/FileUtils.kt
Normal file
47
app/src/main/java/com/zeapo/pwdstore/utils/FileUtils.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
package com.zeapo.pwdstore.utils
|
||||
|
||||
import java.io.File
|
||||
|
||||
object FileUtils {
|
||||
@JvmStatic
|
||||
fun listFiles(dir: File, recursive: Boolean): Collection<File> {
|
||||
val res = ArrayList<File>()
|
||||
val files = dir.listFiles()
|
||||
|
||||
if (files != null && files.isNotEmpty()) {
|
||||
|
||||
files.forEach { file ->
|
||||
// Check if the file is a directory and recursive add
|
||||
if (file.isDirectory && recursive) {
|
||||
res.addAll(listFiles(file, recursive))
|
||||
} else if (!file.isDirectory) {
|
||||
res.add(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getBaseName(filename: String): String {
|
||||
// Take the file name along with its extension
|
||||
val indexName = filename.lastIndexOf('/')
|
||||
val nameWithExtension = filename.substring(indexName + 1)
|
||||
|
||||
// Find the final '.' character in the previously calculated nameWithExtension
|
||||
val indexExt = nameWithExtension.lastIndexOf('.')
|
||||
|
||||
// If no '.' is found in the name, we assume this is a directory and return the previously
|
||||
// derived nameWithExtensions as-is, otherwise we slice out a substring from the first character
|
||||
// to the last occurrence of '.' which we found earlier.
|
||||
return if (indexExt == -1)
|
||||
nameWithExtension
|
||||
else
|
||||
nameWithExtension.substring(0, indexExt)
|
||||
}
|
||||
}
|
@@ -8,7 +8,6 @@ import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import org.apache.commons.io.filefilter.FileFilterUtils
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.Repository
|
||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
|
||||
@@ -195,9 +194,9 @@ open class PasswordRepository protected constructor() {
|
||||
fun getFilesList(path: File?): ArrayList<File> {
|
||||
if (path == null || !path.exists()) return ArrayList()
|
||||
|
||||
val directories = (path.listFiles(FileFilterUtils.directoryFileFilter() as FileFilter)
|
||||
val directories = (path.listFiles(FileFilter { pathname -> pathname.isDirectory })
|
||||
?: emptyArray()).toList()
|
||||
val files = (path.listFiles(FileFilterUtils.suffixFileFilter(".gpg") as FileFilter)
|
||||
val files = (path.listFiles(FileFilter { pathname -> pathname.extension == "gpg" })
|
||||
?: emptyArray()).toList()
|
||||
|
||||
val items = ArrayList<File>()
|
||||
|
@@ -47,8 +47,6 @@ ext.deps = [
|
||||
|
||||
third_party: [
|
||||
bouncycastle: 'org.bouncycastle:bcprov-jdk15on:1.65',
|
||||
commons_io: 'commons-io:commons-io:2.5',
|
||||
commons_codec: 'commons-codec:commons-codec:1.13',
|
||||
fastscroll: 'me.zhanghai.android.fastscroll:library:1.1.4',
|
||||
jsch: 'com.jcraft:jsch:0.1.55',
|
||||
jgit: 'org.eclipse.jgit:org.eclipse.jgit:3.7.1.201504261725-r',
|
||||
|
Reference in New Issue
Block a user