Avoid destination's file outside repository (#861)
This commit is contained in:
parent
23b488a8eb
commit
0a4bcc57f5
4 changed files with 14 additions and 6 deletions
|
@ -66,6 +66,7 @@ import com.zeapo.pwdstore.utils.PasswordRepository.Companion.initialize
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.isInitialized
|
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.isInitialized
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository.PasswordSortOrder.Companion.getSortOrder
|
import com.zeapo.pwdstore.utils.PasswordRepository.PasswordSortOrder.Companion.getSortOrder
|
||||||
import com.zeapo.pwdstore.utils.commitChange
|
import com.zeapo.pwdstore.utils.commitChange
|
||||||
|
import com.zeapo.pwdstore.utils.isInsideRepository
|
||||||
import com.zeapo.pwdstore.utils.listFilesRecursively
|
import com.zeapo.pwdstore.utils.listFilesRecursively
|
||||||
import com.zeapo.pwdstore.utils.requestInputFocusOnView
|
import com.zeapo.pwdstore.utils.requestInputFocusOnView
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -666,15 +667,11 @@ class PasswordStore : AppCompatActivity(R.layout.activity_pwdstore) {
|
||||||
}.launch(intent)
|
}.launch(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isInsideRepository(file: File): Boolean {
|
|
||||||
return file.canonicalPath.contains(getRepositoryDirectory(this).canonicalPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class CategoryRenameError(val resource: Int) {
|
enum class CategoryRenameError(val resource: Int) {
|
||||||
None(0),
|
None(0),
|
||||||
EmptyField(R.string.message_category_error_empty_field),
|
EmptyField(R.string.message_category_error_empty_field),
|
||||||
CategoryExists(R.string.message_category_error_category_exists),
|
CategoryExists(R.string.message_category_error_category_exists),
|
||||||
DestinationOutsideRepo(R.string.message_category_error_destination_outside_repo),
|
DestinationOutsideRepo(R.string.message_error_destination_outside_repo),
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,6 +18,7 @@ import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.ajalt.timberkt.e
|
import com.github.ajalt.timberkt.e
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.zeapo.pwdstore.PasswordEntry
|
import com.zeapo.pwdstore.PasswordEntry
|
||||||
|
import com.zeapo.pwdstore.utils.isInsideRepository
|
||||||
import com.zeapo.pwdstore.R
|
import com.zeapo.pwdstore.R
|
||||||
import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences
|
import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences
|
||||||
import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure
|
import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure
|
||||||
|
@ -235,6 +236,11 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
|
||||||
snackbar(message = getString(R.string.password_creation_duplicate_error))
|
snackbar(message = getString(R.string.password_creation_duplicate_error))
|
||||||
return@executeApiAsync
|
return@executeApiAsync
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isInsideRepository(file)) {
|
||||||
|
snackbar(message = getString(R.string.message_error_destination_outside_repo))
|
||||||
|
return@executeApiAsync
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
file.outputStream().use {
|
file.outputStream().use {
|
||||||
it.write(outputStream.toByteArray())
|
it.write(outputStream.toByteArray())
|
||||||
|
|
|
@ -23,6 +23,7 @@ import androidx.security.crypto.EncryptedSharedPreferences
|
||||||
import androidx.security.crypto.MasterKey
|
import androidx.security.crypto.MasterKey
|
||||||
import com.github.ajalt.timberkt.d
|
import com.github.ajalt.timberkt.d
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import com.zeapo.pwdstore.PasswordStore
|
||||||
import com.zeapo.pwdstore.git.GitAsyncTask
|
import com.zeapo.pwdstore.git.GitAsyncTask
|
||||||
import com.zeapo.pwdstore.git.GitOperation
|
import com.zeapo.pwdstore.git.GitOperation
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getRepositoryDirectory
|
import com.zeapo.pwdstore.utils.PasswordRepository.Companion.getRepositoryDirectory
|
||||||
|
@ -123,3 +124,7 @@ fun <T : View> AlertDialog.requestInputFocusOnView(@IdRes id: Int) {
|
||||||
val Context.autofillManager: AutofillManager?
|
val Context.autofillManager: AutofillManager?
|
||||||
@RequiresApi(Build.VERSION_CODES.O)
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
get() = getSystemService()
|
get() = getSystemService()
|
||||||
|
|
||||||
|
fun Activity.isInsideRepository(file: File): Boolean {
|
||||||
|
return file.canonicalPath.contains(getRepositoryDirectory(this).canonicalPath)
|
||||||
|
}
|
||||||
|
|
|
@ -327,7 +327,7 @@
|
||||||
<string name="title_rename_folder">Rename folder</string>
|
<string name="title_rename_folder">Rename folder</string>
|
||||||
<string name="message_category_error_empty_field">Category name can\'t be empty</string>
|
<string name="message_category_error_empty_field">Category name can\'t be empty</string>
|
||||||
<string name="message_category_error_category_exists">Category name already exists</string>
|
<string name="message_category_error_category_exists">Category name already exists</string>
|
||||||
<string name="message_category_error_destination_outside_repo">Destination must be within the repository</string>
|
<string name="message_error_destination_outside_repo">Destination must be within the repository</string>
|
||||||
<string name="message_rename_folder">Enter destination for %1$s</string>
|
<string name="message_rename_folder">Enter destination for %1$s</string>
|
||||||
<string name="button_create">Create</string>
|
<string name="button_create">Create</string>
|
||||||
<string name="pref_search_on_start">Open search on start</string>
|
<string name="pref_search_on_start">Open search on start</string>
|
||||||
|
|
Loading…
Reference in a new issue