diff --git a/companion/README.md b/companion/README.md index cb4a717..dcb5960 100644 --- a/companion/README.md +++ b/companion/README.md @@ -69,7 +69,7 @@ am start-foreground-service \ # 2) first-run consent (VISIBLE Activity, the one unavoidable UI step) am start \ -n ru.vd171.vdbackup/.ConsentActivity \ - -e result /data/adb/vdbackup/drive/consent.json + -e result /data/data/ru.vd171.vdbackup/files/consent.json # user signs in; result JSON: ok=true code=ERR_NONE, or ok=false code=ERR_CONSENT_DENIED ``` diff --git a/companion/app/src/main/kotlin/ru/vd171/vdbackup/ConsentActivity.kt b/companion/app/src/main/kotlin/ru/vd171/vdbackup/ConsentActivity.kt index e83584a..a4ace75 100644 --- a/companion/app/src/main/kotlin/ru/vd171/vdbackup/ConsentActivity.kt +++ b/companion/app/src/main/kotlin/ru/vd171/vdbackup/ConsentActivity.kt @@ -31,6 +31,7 @@ import com.google.android.gms.auth.api.signin.GoogleSignInClient import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.android.gms.common.api.ApiException import com.google.android.gms.common.api.Scope +import java.io.File class ConsentActivity : Activity() { @@ -71,13 +72,21 @@ class ConsentActivity : Activity() { } private fun finishWith(ok: Boolean, code: String, msg: String? = null) { - intent.getStringExtra(EXTRA_RESULT)?.let { path -> - CommandResult.write(path, ok, "consent", code, null, msg ?: if (ok) "consent granted" else "consent denied") + resultFile()?.let { f -> + CommandResult.write(f.path, ok, "consent", code, null, msg ?: if (ok) "consent granted" else "consent denied") } setResult(if (ok) RESULT_OK else RESULT_CANCELED) finish() } + // The Activity is exported (root starts it with `am start`), so the result path + // comes from any caller: accept only a consent.* file directly in our files dir. + private fun resultFile(): File? { + val path = intent.getStringExtra(EXTRA_RESULT) ?: return null + val f = runCatching { File(path).canonicalFile }.getOrNull() ?: return null + return f.takeIf { it.parentFile == filesDir.canonicalFile && it.name.startsWith("consent.") } + } + companion object { private const val RC_SIGN_IN = 0x7D1 const val EXTRA_RESULT = "result" diff --git a/module/scripts/worker.sh b/module/scripts/worker.sh index cc63ee9..23957eb 100644 --- a/module/scripts/worker.sh +++ b/module/scripts/worker.sh @@ -832,6 +832,14 @@ item_paths() { # every backend namespaces its data under /vdbackup so our files never # collide with the user's other files at the chosen destination path. remote_pfx() { printf '%s' "${DPATH:+$DPATH/}vdbackup"; } +# A local Mirror needs an absolute, allowed root: the default local destination has no path, +# which would make remote_pfx relative to the worker's cwd. Default it to a hidden dir in the +# user's backups dir, then apply the same storage allowlist as a full backup's local copy. +mirror_local_dest() { + [ "$DTYPE" = local ] || return 0 + [ -n "$DPATH" ] || DPATH="$(backups_dir "$U")/.mirror" + safe_local_dest "$DPATH" || { audit "refused unsafe local dest $DPATH $PKG"; finish false ERR_DEST_UNSAFE; return 1; } +} # Live rclone transfer: run rclone with periodic one-line stats and feed progx so the # WebUI shows percent / speed / ETA. A sentinel file carries rclone's real exit code @@ -967,8 +975,10 @@ do_snapshot() { do_mirror() { [ -n "$DREMOTE" ] || [ "$DTYPE" = local ] || { finish false ERR_NO_DEST; return; } [ "$DTYPE" = local ] || net_guard || return + mirror_local_dest || return prog 5 freezing "$PKG"; notify backup_start "$PKG" freeze "$PKG" + _bfail=0 # APK: always compressed, never raw (even in a mirror) if echo " $ITEMS " | grep -q ' apk '; then prog 18 mirror apk @@ -978,10 +988,9 @@ do_mirror() { case "$DTYPE" in local) mkdir -p "$(remote_pfx)/$PKG/apk" && exec_ns "$RSYNC" -a --delete "$apkdir/" "$(remote_pfx)/$PKG/apk/" >/dev/null 2>&1 ;; rclone) rclone_live "mirror apk" 18 sync "$apkdir" "$DREMOTE:$(remote_pfx)/$PKG/apk" ;; - esac + esac || { _bfail=1; audit "mirror sync failed $PKG (apk)"; } rm -rf "$apkdir" fi - _bfail=0 sync_one() { #