2 Commits
v1.6 ... v1.8

Author SHA1 Message Date
sakuradairong
7fec4c52a1 release: v1.8
fix: 桥接器 socket 超时 = 0(禁用),restic 密钥生成不限时
fix: 去掉应用层超时兜底,让 init 自然完成
feat: streamBodyToFile 添加耗时日志(可观察密钥生成耗时)
2026-06-06 00:01:23 +08:00
sakuradairong
32182b592e release: v1.7
chore: 桥接器超时 60s,应用层超时 60s(按用户反馈)
2026-06-05 23:55:25 +08:00
3 changed files with 15 additions and 19 deletions

View File

@@ -26,8 +26,8 @@ android {
applicationId "com.example.androidbackupgui"
minSdk 24
targetSdk 34
versionCode 7
versionName "1.6"
versionCode 9
versionName "1.8"
}
buildFeatures {
viewBinding true

View File

@@ -110,13 +110,19 @@ class ResticRestBridge(
* Returns the temp file (caller must delete).
*/
private fun streamBodyToFile(session: IHTTPSession, tmpDir: File): Result<File> {
val started = System.currentTimeMillis()
return try {
val tmpFile = File(tmpDir, "restic_blob_${UUID.randomUUID()}")
val input = (session as NanoHTTPD.HTTPSession).inputStream
Log.d(TAG, "streamBodyToFile: reading body...")
tmpFile.outputStream().use { output -> input.copyTo(output) }
val elapsed = System.currentTimeMillis() - started
val bytes = tmpFile.length()
Log.i(TAG, "streamBodyToFile: read $bytes bytes in ${elapsed}ms")
Result.success(tmpFile)
} catch (e: Exception) {
Log.w(TAG, "stream body to file failed", e)
val elapsed = System.currentTimeMillis() - started
Log.w(TAG, "streamBodyToFile failed after ${elapsed}ms", e)
Result.failure(e)
}
}

View File

@@ -18,7 +18,6 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeoutOrNull
import java.io.File
import java.util.concurrent.atomic.AtomicBoolean
@@ -190,21 +189,12 @@ class ConfigViewModel(application: Application) : AndroidViewModel(application)
viewModelScope.launch {
try {
_operationEvents.emit(OperationEvent.InitStarted)
val result = withTimeoutOrNull(15 * 60 * 1000L) {
ResticWrapper.init(form.repo, form.password,
backend = form.backend, backendUrl = form.backendUrl,
backendUser = form.backendUser, backendPass = form.backendPass,
backendShare = form.backendShare,
)
}
if (result == null) {
_operationEvents.emit(OperationEvent.InitFailed)
Log.w(TAG, "initResticRepo timed out after 15 minutes")
_uiState.update { it.copy(resticStatus = it.resticStatus.copy(
message = "初始化超时15分钟请检查网络/SMB 服务器是否正常"
))}
refreshResticStatus(form)
} else if (result.isSuccess) {
val result = ResticWrapper.init(form.repo, form.password,
backend = form.backend, backendUrl = form.backendUrl,
backendUser = form.backendUser, backendPass = form.backendPass,
backendShare = form.backendShare,
)
if (result.isSuccess) {
_operationEvents.emit(OperationEvent.InitCompleted)
_uiState.update { it.copy(resticStatus = it.resticStatus.copy(
message = "仓库初始化成功: ${form.repo}"