aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt
diff options
context:
space:
mode:
authorFabian Henneke <FabianHenneke@users.noreply.github.com>2020-09-11 09:58:03 +0200
committerGitHub <noreply@github.com>2020-09-11 13:28:03 +0530
commit7a58e397a9323476fcea5d1556b4996e474dc15e (patch)
tree797359ddeaf81094e3ad8eea8736bf672e39ad91 /app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt
parent9cb8551a90c10b22ef1c81ffcf00a84e1d9144f9 (diff)
downloadHardenedPass-7a58e397a9323476fcea5d1556b4996e474dc15e.tar.gz
HardenedPass-7a58e397a9323476fcea5d1556b4996e474dc15e.zip
Disable SSH multiplexing if not supported (#1093)
Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt
index a15972c1..19413efd 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt
@@ -11,6 +11,8 @@ import com.github.ajalt.timberkt.d
import com.github.ajalt.timberkt.e
import com.github.michaelbull.result.Err
import com.github.michaelbull.result.Result
+import com.github.michaelbull.result.andThen
+import com.github.michaelbull.result.mapError
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.zeapo.pwdstore.R
import com.zeapo.pwdstore.git.config.GitSettings
@@ -42,6 +44,11 @@ abstract class BaseGitActivity : AppCompatActivity() {
if (GitSettings.url == null) {
return Err(IllegalStateException("Git url is not set!"))
}
+ if (operation == REQUEST_SYNC && !GitSettings.useMultiplexing) {
+ // If the server does not support multiple SSH channels per connection, we cannot run
+ // a sync operation without reconnecting and thus break sync into its two parts.
+ return launchGitOperation(REQUEST_PULL).andThen { launchGitOperation(REQUEST_PUSH) }
+ }
val op = when (operation) {
REQUEST_CLONE, GitOperation.GET_SSH_KEY_FROM_CLONE -> CloneOperation(this, GitSettings.url!!)
REQUEST_PULL -> PullOperation(this)
@@ -54,7 +61,15 @@ abstract class BaseGitActivity : AppCompatActivity() {
return Err(IllegalArgumentException("$operation is not a valid Git operation"))
}
}
- return op.executeAfterAuthentication(GitSettings.authMode)
+ return op.executeAfterAuthentication(GitSettings.authMode).mapError { throwable ->
+ val err = rootCauseException(throwable)
+ if (err.message?.contains("cannot open additional channels") == true) {
+ GitSettings.useMultiplexing = false
+ SSHException(DisconnectReason.TOO_MANY_CONNECTIONS, "The server does not support multiple Git operations per SSH session. Please try again, a slower fallback mode will be used.")
+ } else {
+ err
+ }
+ }
}
fun finishOnSuccessHandler(@Suppress("UNUSED_PARAMETER") nothing: Unit) {