aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorLena <lena@omega>2026-07-01 00:00:00 +0000
committerLena <lena@omega>2026-07-01 00:00:00 +0000
commitf3889d4fb5659c94f4ec957219bebada8d1a67fb (patch)
treedaf70c1c4a27653a53a85651bf51eb0cec43ed24 /app/src/main/java
parent0d8ef6c605ab646cb6fc7e5eaaefe40ef1de95ee (diff)
downloadrsend-f3889d4fb5659c94f4ec957219bebada8d1a67fb.tar.gz
app: refuse folder mappings with empty paths
The trailing-slash fix-up turns an empty local path into /, so a blank folder row would rsync the entire filesystem; an empty remote path pushes into the rrsync root. Reject both when saving a folder, skip and log them at run time in case the config was edited by hand, and log why a sync was skipped when the app is not configured yet.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/invalid/lena/rsend/FolderEditActivity.kt13
-rw-r--r--app/src/main/java/invalid/lena/rsend/SyncWorker.kt7
2 files changed, 16 insertions, 4 deletions
diff --git a/app/src/main/java/invalid/lena/rsend/FolderEditActivity.kt b/app/src/main/java/invalid/lena/rsend/FolderEditActivity.kt
index c61276c..466a859 100644
--- a/app/src/main/java/invalid/lena/rsend/FolderEditActivity.kt
+++ b/app/src/main/java/invalid/lena/rsend/FolderEditActivity.kt
@@ -64,13 +64,13 @@ class FolderEditActivity : AppCompatActivity() {
)
}
- findViewById<Button>(R.id.save).setOnClickListener { saveFolder(); finish() }
+ findViewById<Button>(R.id.save).setOnClickListener { if (saveFolder()) finish() }
val del = findViewById<Button>(R.id.removeFolder)
del.visibility = if (index < 0) View.GONE else View.VISIBLE
del.setOnClickListener { removeFolder(); finish() }
}
- private fun saveFolder() {
+ private fun saveFolder(): Boolean {
val f = Folder(
name = name.text.toString().trim(),
local = local.text.toString().trim(),
@@ -78,13 +78,20 @@ class FolderEditActivity : AppCompatActivity() {
delete = delete.isChecked,
excludes = excludes.text.toString().split(",").map { it.trim() }.filter { it.isNotEmpty() },
)
- if (f.local.isNotEmpty() && !File(f.local).exists()) {
+ // An empty path would rsync / (local) or the rrsync root (remote):
+ // refuse rather than sync the world.
+ if (f.local.isEmpty() || f.remote.isEmpty()) {
+ Toast.makeText(this, "Set both local and remote paths first.", Toast.LENGTH_LONG).show()
+ return false
+ }
+ if (!File(f.local).exists()) {
Toast.makeText(this, "Warning: local path does not exist yet.", Toast.LENGTH_LONG).show()
}
val cfg = Config.load(this)
val list = cfg.folders.toMutableList()
if (index in list.indices) list[index] = f else list.add(f)
Config.save(this, cfg.copy(folders = list))
+ return true
}
private fun removeFolder() {
diff --git a/app/src/main/java/invalid/lena/rsend/SyncWorker.kt b/app/src/main/java/invalid/lena/rsend/SyncWorker.kt
index f4607ea..a70a3e6 100644
--- a/app/src/main/java/invalid/lena/rsend/SyncWorker.kt
+++ b/app/src/main/java/invalid/lena/rsend/SyncWorker.kt
@@ -30,6 +30,7 @@ class SyncWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(ctx,
val startedAt = System.currentTimeMillis()
val cfg = Config.load(ctx)
if (cfg.remote.host.isEmpty() || cfg.folders.isEmpty() || !Keys.exists(ctx) || !Keys.pinned(ctx)) {
+ SyncLog(ctx).line("sync skipped: remote, folders, key, or pinned host missing")
return@withContext Result.success()
}
@@ -54,7 +55,11 @@ class SyncWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(ctx,
// Publish progress the dashboard observes (current folder, i of n).
setProgress(workDataOf(KEY_FOLDER to label, KEY_INDEX to i + 1, KEY_TOTAL to total))
log.line("=== $label ===")
- val code = try {
+ // Guard against a hand-edited config: an empty path would rsync /.
+ val code = if (f.local.isEmpty() || f.remote.isEmpty()) {
+ log.line("error: local or remote path not set")
+ 1
+ } else try {
RsyncRunner.runFolder(ctx, cfg.remote, f, log)
} catch (e: Exception) {
log.line("error: ${e.message}")