fix: Sync-Fehler "error decoding response body" + Server-Edits

Drei Probleme in einem:

1. create_folder/get_sync_tree parsten die Response auch bei HTTP-
   Fehlern als JSON. Bei 401/409/etc. kam "error decoding response
   body" statt der eigentlichen Fehlermeldung. Status wird jetzt
   zuerst geprueft, Body-Text wird bei Fehlern zurueckgegeben.

2. Ohne Journal-Eintrag und unterschiedlichen Hashes wurde vorher
   eine Konflikt-Kopie erstellt. Fuer Server-Edits aus dem Web-UI
   (wo der Client die Datei gar nie mit Journal erfasst hatte) war
   das falsch. Nextcloud-Ansatz: beim Erstkontakt Server
   autoritativ - Download statt Konflikt-Kopie.

3. run_sync_now uebernimmt neu konfigurierte sync_paths aus dem
   State, damit manuelle Syncs auch nach add_sync_path greifen.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Hacker 2026-04-12 10:25:01 +02:00
parent 28fb1c47c2
commit 5f905b4925
3 changed files with 22 additions and 4 deletions

View File

@ -244,6 +244,8 @@ async fn run_sync_now(state: State<'_, AppState>) -> Result<Vec<String>, String>
if let Some(ref api) = *state.api.lock().unwrap() {
engine.api.access_token = api.access_token.clone();
}
// Refresh sync_paths from state: user may have added/removed paths
engine.sync_paths = state.sync_paths.lock().unwrap().clone();
let result = engine.sync_all().await;
*state.sync_engine.lock().unwrap() = Some(engine);
result

View File

@ -124,8 +124,13 @@ impl MiniCloudApi {
.await
.map_err(|e| format!("Sync-Tree Fehler: {}", e))?;
if !resp.status().is_success() {
let status = resp.status();
let text = resp.text().await.unwrap_or_default();
return Err(format!("Sync-Tree HTTP {}: {}", status, text));
}
let data: SyncTreeResponse = resp.json().await
.map_err(|e| format!("Parse-Fehler: {}", e))?;
.map_err(|e| format!("Sync-Tree Parse-Fehler: {}", e))?;
Ok(data.tree)
}
@ -204,9 +209,14 @@ impl MiniCloudApi {
.json(&body)
.send()
.await
.map_err(|e| e.to_string())?;
.map_err(|e| format!("Create-Folder Verbindungsfehler: {}", e))?;
resp.json().await.map_err(|e| e.to_string())
if !resp.status().is_success() {
let status = resp.status();
let text = resp.text().await.unwrap_or_default();
return Err(format!("Create-Folder fehlgeschlagen ({}): {}", status, text));
}
resp.json().await.map_err(|e| format!("Create-Folder Parse-Fehler: {}", e))
}
pub async fn lock_file(&self, file_id: i64, client_info: &str) -> Result<(), String> {

View File

@ -274,7 +274,13 @@ impl SyncEngine {
let (local_changed, server_changed) = match &journal_entry {
Some(j) => (local_hash != j.synced_checksum, server_hash != j.synced_checksum),
None => (true, true), // unknown history - treat as conflict to be safe
None => {
// No journal history: this is the first time we're tracking
// this file. Treat the server as authoritative (Nextcloud
// does the same on first sync) so edits made on the web
// GUI or other clients propagate down cleanly.
(false, true)
}
};
if local_changed && !server_changed {