aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-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}")