@@ -51,14 +51,28 @@ class ResticRepository @Inject constructor(
5151 )
5252 defaultEnv.putAll(env)
5353
54- // 构建带环境变量的命令
54+ // 详细日志记录
55+ Log .d(TAG , " === Restic Command Debug ===" )
56+ Log .d(TAG , " Command: restic ${args.joinToString(" " )} " )
57+ Log .d(TAG , " Environment: ${defaultEnv.entries.joinToString(" , " ) { " ${it.key} =${it.value} " }} " )
58+
5559 val envExports = defaultEnv.map { " export ${it.key} =\" ${it.value} \" " }
5660 val command = envExports.joinToString(" && " ) + " && $resticPath ${args.joinToString(" " )} "
5761
58- Log .d(TAG , " Executing Root Command : $command " )
62+ Log .d(TAG , " Full command : $command " )
5963
6064 val result = Shell .cmd(command).exec()
61- logger.logCommandResult(result.code, result.out .joinToString(" \n " ))
65+
66+ // 详细输出日志
67+ Log .d(TAG , " Exit code: ${result.code} " )
68+ if (result.out .isNotEmpty()) {
69+ Log .d(TAG , " STDOUT:\n ${result.out .joinToString(" \n " )} " )
70+ }
71+ if (result.err.isNotEmpty()) {
72+ Log .e(TAG , " STDERR:\n ${result.err.joinToString(" \n " )} " )
73+ }
74+ Log .d(TAG , " ==============================" )
75+
6276 result
6377 }
6478
@@ -360,22 +374,55 @@ class ResticRepository @Inject constructor(
360374 ): Result <String > {
361375 val repoUrl = buildS3ResticUrl(extra, remotePath)
362376
363- // 设置环境变量
377+ // 完整的环境变量设置
364378 val env = mutableMapOf (
365379 " AWS_ACCESS_KEY_ID" to extra.accessKeyId,
366380 " AWS_SECRET_ACCESS_KEY" to extra.secretAccessKey,
367381 " RESTIC_PASSWORD" to password
368382 )
369383
370- // 对于非 AWS 的 S3 兼容存储,可能需要额外设置
384+ // 根据文档添加必要的配置
385+ val options = mutableListOf<String >()
386+
371387 if (extra.endpoint.isNotEmpty()) {
372- // 设置自定义 region(如果 endpoint 不是 AWS)
388+ // 自定义endpoint的S3兼容存储
373389 if (extra.region.isNotEmpty()) {
374390 env[" AWS_DEFAULT_REGION" ] = extra.region
391+ options.add(" -o" )
392+ options.add(" s3.region=${extra.region} " )
375393 }
394+
395+ // 对于非AWS存储,可能需要指定bucket-lookup模式
396+ if (! extra.endpoint.contains(" amazonaws.com" )) {
397+ options.add(" -o" )
398+ options.add(" s3.bucket-lookup=dns" )
399+ }
400+ } else {
401+ // AWS S3特定配置
402+ env[" AWS_DEFAULT_REGION" ] = extra.region
376403 }
377404
378- return initRepository(repoUrl, password)
405+ // 构建完整的命令参数
406+ val args = mutableListOf (" init" , " --repo" , " \" $repoUrl \" " )
407+ args.addAll(options)
408+
409+ // 直接调用executeRestic而不是initRepository
410+ val result = executeRestic(
411+ * args.toTypedArray(),
412+ env = env
413+ )
414+
415+ val output = if (result.isSuccess) {
416+ result.out .joinToString(" \n " )
417+ } else {
418+ result.err.joinToString(" \n " )
419+ }
420+
421+ return if (result.isSuccess) {
422+ Result .success(output)
423+ } else {
424+ Result .failure(Exception (output.ifEmpty { " Unknown error during restic init" }))
425+ }
379426 }
380427
381428 /* *
0 commit comments