Hostname/sync-folder: case-only legacy folder deletes the SAF mirror; device rename half-migrates; non-Latin names become 'unknown'

Abierto
#402 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@TimeToBuildBob ya está trabajando en esto.

Desde el 24/11/2026.

  • #403 de @TimeToBuildBob — abierto
  • #404 de @TimeToBuildBob — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
android, kotlin, sqlite
Área
database, mobile

Línea de trabajo

Start with the JVM repros: planFolderMigration and sanitizeDeviceHostname in the hostname and sync-folder code, plus SanitizedHostnameMigration.legacyHostnames, renameDir, SyncInterface.deleteStaleSafHostnameDirs and DatastoreStartup.rewriteBucketHostnames. Done means the case-only and non-Latin repros behave as described, and a rename moves existing buckets and the sync folder consistently. The issue asks for a decision on whether history should move, so confirm that with maintainers before coding.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Three hostname and sync-folder defects found in a review of master (aa9cea0). Each is confirmed by reading the code; the reproduction steps below name the pure functions involved. Fix order matters: fixing 3 changes existing hostnames, which runs into 2.

1. Case-only legacy folder: the SAF mirror of this device is deleted after every sync

Two independent reviewers reported this. Take a raw device name like PIXEL8 or Bob: the legacy folder is PIXEL8, and the sanitized hostname is pixel8.

  • SanitizedHostnameMigration.legacyHostnames filters with a case-sensitive compare (it != current), so PIXEL8 counts as legacy.
  • getExternalFilesDir()/sync sits on Android's case-insensitive emulated storage. planFolderMigration plans RenameHostnameDir("PIXEL8", "pixel8"). renameDir then refuses, because File("pixel8").exists() is the same directory. The migration is never marked done and re-runs on every sync.
  • aw-sync's writes to pixel8/ land in the existing PIXEL8/. The mirror copies them to SAF PIXEL8/<device_id>/.
  • SyncInterface.deleteStaleSafHostnameDirs then matches the legacy name PIXEL8 and deletes <device_id> and the folder.

Result: after every successful sync, the Syncthing folder holds none of this device's data, and peers see it appear and disappear.

JVM repro of the planning step: planFolderMigration(setOf("PIXEL8"), mapOf("PIXEL8" to setOf("id")), "pixel8", listOf("PIXEL8"), "id") returns a rename onto the same directory. The refused rename and the deletion need a case-insensitive filesystem.

Likely fix: in the folder paths (planner and SAF cleanup) only, treat a legacy name that equals the current one ignoring case as the current folder. A case-only rename needs a two-step rename. The bucket-hostname rewrite in sqlite.db should stay case-sensitive.

2. Renaming the device leaves the existing buckets on the old hostname, and the rewrite never retries

Device Pixel 7 → hostname pixel_7. The user renames it to Erik's Pixel → erik_s_pixel.

  • DatastoreStartup.rewriteBucketHostnames only rewrites hostnames in legacyHostnames(current, rawDeviceName, MODEL) = ["Erik's Pixel", "Pixel 7", "Unknown", "unknown"]. These are raw names, so the stored sanitized pixel_7 never matches.
  • It updates 0 rows and, because of updated >= 0, still stores sanitizedHostnameMigratedTo = erik_s_pixel. It never retries.
  • Existing buckets keep pixel_7, while /api/0/info, new buckets, the dashboard route /#/activity/erik_s_pixel/ and the sync folder all use the new name. The pixel_7/<id>/ sync folder is never migrated either.

The previous sanitized hostname is already in that preference; it just isn't added to the candidates. Whether a rename should move history to the new name is a product decision, but the current half-moved state is a bug either way.

3. Device names without Latin letters become the unknown sentinel

deviceHostname() only falls back to Build.DEVICE when DEVICE_NAME is null. Names like 小米手机, Телефон or 📱 sanitize to unknown, the value the KDoc calls a terrible default. aw-sync then treats the device as having no provenance. Mixed names can also collide: Galaxy Пети and Galaxy Маши both become galaxy.

JVM repro: sanitizeDeviceHostname("小米手机") == "unknown". A fix should fall back to Build.DEVICE when the sanitized name is unknown.

Lenguaje dominante
Kotlin
Estrellas
289
Forks
67
Merge medio
8 d 52 min
PR fusionados (30 d)
8

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ActivityWatch/aw-android

Todos los issues de ActivityWatch/aw-android

Issues similares

Más issues de Kotlin

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.