From c57d98799a618f72d7330e476ec08150884b1730 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Thu, 19 Nov 2026 05:01:52 +0100 Subject: [PATCH] fix(sync): explain moves blocked by Trash Keep blocked moves queued so they can land after a restore. Retain simulation logs for intermittent conflicts and pick up the SDK fix for uploads from machines with fast clocks. --- .github/workflows/ci.yml | 13 ++- Cargo.lock | 8 +- Cargo.toml | 4 +- crates/pdfs-cli/src/main.rs | 1 + crates/pdfs-core/src/control.rs | 4 + crates/pdfs-fuse/src/drain.rs | 111 ++++++++++++++++++--- crates/pdfs-fuse/src/sim/daemon.rs | 62 ++++++++++++ crates/pdfs-fuse/src/sim/fake_drive.rs | 17 ++++ crates/pdfs-fuse/src/sim/run.rs | 4 + crates/pdfs-gui/src/app/pages/locations.rs | 3 + docs/BUGS.md | 7 +- docs/CHANGELOG.md | 16 ++- docs/TESTING.md | 3 +- 13 files changed, 222 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67d836c..bc5cf39 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,14 +105,17 @@ jobs: - name: Simulation runs run: 'cargo test -p pdfs-fuse --lib --locked sim:: -- --ignored --test-threads=1' - # A hung step writes every daemon thread's stack next to the run's - # state; without them a hang that does not replay cannot be told apart. - - name: Keep the stacks of a hung run + # Retain the operation trace and daemon logs for the failing seed, plus + # every daemon thread's stack if the watchdog caught a hang. + - name: Keep simulation failure diagnostics if: failure() uses: actions/upload-artifact@v7 with: - name: simulation-stacks - path: /tmp/pdfs-sim-*/stacks.txt + name: simulation-diagnostics + path: | + /tmp/pdfs-sim-*/steps.log + /tmp/pdfs-sim-*/daemon.log + /tmp/pdfs-sim-*/stacks.txt if-no-files-found: ignore # Keeps the release-profile dependencies cached on main, where the release diff --git a/Cargo.lock b/Cargo.lock index 0a4ee4e..cdb2d44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3893,9 +3893,9 @@ dependencies = [ [[package]] name = "proton-drive-rs" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4265c2cf3bdc59ee273d7363c8b6a7cb4e98be6102ffa18144c4d8ebda00737b" +checksum = "d05ad4be849ce2104759631063dd06867fbe6b6f0e5c37a172a84b5a90203fa7" dependencies = [ "async-trait", "base64 0.23.1", @@ -3921,9 +3921,9 @@ dependencies = [ [[package]] name = "proton-sdk" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb98ab3e336ed95f82368a50348dad00e5fc919e982d748e83e844afcadbd5d8" +checksum = "80c381e9066c0bca3c32597df2e902eecaa4c6e05e202e70ec9d0ac2eec78bfe" dependencies = [ "aes-gcm 0.11.1", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 8628ced..bcd827d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ keywords = ["proton", "drive", "fuse", "sync", "linux"] categories = ["filesystem", "command-line-utilities"] [workspace.dependencies] -proton-sdk = { version = "0.12.0" } -proton-drive-rs = { version = "0.12.0" } +proton-sdk = { version = "0.12.1" } +proton-drive-rs = { version = "0.12.1" } chrono = { version = "0.4", default-features = false, features = ["std"] } # Internal crates. diff --git a/crates/pdfs-cli/src/main.rs b/crates/pdfs-cli/src/main.rs index 2fc2e17..f6692ed 100644 --- a/crates/pdfs-cli/src/main.rs +++ b/crates/pdfs-cli/src/main.rs @@ -1511,6 +1511,7 @@ fn issue_text(issue: SyncIssue) -> &'static str { "you can no longer change this on Proton Drive, for example because a share was \ revoked. Save a copy to keep the content." } + SyncIssue::Trashed => "restore the item or folder from Trash, then retry the move.", SyncIssue::Missing => { "the file or its folder is gone from Proton Drive. Save a copy to keep the content." } diff --git a/crates/pdfs-core/src/control.rs b/crates/pdfs-core/src/control.rs index 7ef2881..e82fd9e 100644 --- a/crates/pdfs-core/src/control.rs +++ b/crates/pdfs-core/src/control.rs @@ -964,6 +964,8 @@ pub enum SyncIssue { /// The account may no longer change the file or its folder, for example /// because a share was revoked. Access, + /// The item or a folder involved in a move can be restored from Trash. + Trashed, /// The file or the folder it goes into is gone from Drive. Missing, /// The folder holds too many items, or is nested too deep. @@ -981,6 +983,7 @@ impl SyncIssue { match self { SyncIssue::Quota => "quota", SyncIssue::Access => "access", + SyncIssue::Trashed => "trashed", SyncIssue::Missing => "missing", SyncIssue::Limit => "limit", SyncIssue::Rejected => "rejected", @@ -993,6 +996,7 @@ impl SyncIssue { match name { "quota" => SyncIssue::Quota, "access" => SyncIssue::Access, + "trashed" => SyncIssue::Trashed, "missing" => SyncIssue::Missing, "limit" => SyncIssue::Limit, "rejected" => SyncIssue::Rejected, diff --git a/crates/pdfs-fuse/src/drain.rs b/crates/pdfs-fuse/src/drain.rs index 34d32e8..a4dd878 100644 --- a/crates/pdfs-fuse/src/drain.rs +++ b/crates/pdfs-fuse/src/drain.rs @@ -20,7 +20,7 @@ //! are kept as a conflict copy rather than discarded — see //! [`Core::revision_conflict`]. -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::fs::File; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -53,6 +53,21 @@ use super::{ use proton_drive_rs::proton_sdk::api::ResponseCode; use proton_drive_rs::proton_sdk::error::ProtonError; +#[derive(Debug)] +struct TrashedMove(String); + +impl std::fmt::Display for TrashedMove { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "‘{}’ is in Proton Drive Trash. Restore it before retrying this move.", + self.0 + ) + } +} + +impl std::error::Error for TrashedMove {} + const DRAIN_ACCESS_RECHECK: Duration = Duration::from_secs(5); /// How long an op may stay access-deferred before the deferral is reported as a @@ -795,13 +810,13 @@ impl Core { let parent = parse_node_uid(parent_str).ok_or("rename op has an unparseable parent")?; let name = op.name.clone().ok_or("rename op has no name")?; - // The node we were asked to rename may be gone or trashed by now. Either - // way there is nothing to rename and nothing to lose — a rename holds no - // bytes — so the op is satisfied rather than retried forever. + // A trashed node can be restored. Only retire the operation if the node + // is gone entirely. let node = match self.fetch_node_remote(&uid)? { - Some(n) if !n.trashed => n, - _ => { - warn!(%uid, name, "renamed node is gone or trashed remotely; dropping the rename"); + Some(n) if n.trashed => return Err(TrashedMove(n.name).into()), + Some(n) => n, + None => { + warn!(%uid, name, "renamed node is gone remotely; dropping the rename"); self.db.delete_op(op.id)?; return Ok(()); } @@ -827,23 +842,38 @@ impl Core { // no window for the requirements to go stale between two calls — // the race B46 queued this op to get away from. let target = (node.name != name).then_some(name.as_str()); - match self.move_rename_remote(&uid, &parent, target) { + let try_move = |target| { + self.move_rename_remote(&uid, &parent, target).map_err( + |error| -> Box { + if (is_gone(&error) || refusal(&error) == Some(Some(SyncIssue::Access))) + && let Some(name) = trashed_move_folder( + node.parent_uid.iter().chain(std::iter::once(&parent)), + |uid| self.fetch_node_remote(uid).ok().flatten(), + ) + { + return TrashedMove(name).into(); + } + error.into() + }, + ) + }; + match try_move(target) { Ok(()) => name.clone(), // The destination holds that name already. Landing under a // *different* name is the non-destructive resolution: it neither // clobbers their file nor drops ours, and it is visible. - Err(e) if is_already_exists(&e) => { + Err(e) if is_already_exists(e.as_ref()) => { if self.name_is_held(op, Some(&parent), &name)? { return Err(held_by_queued_change(&name)); } // What held it may have let go since Drive answered // (docs/BUGS.md B144). - match self.move_rename_remote(&uid, &parent, target) { + match try_move(target) { Ok(()) => name.clone(), - Err(e) if is_already_exists(&e) => { + Err(e) if is_already_exists(e.as_ref()) => { let alt = conflict_name(&name, now_secs()); warn!(%uid, name, alt, "destination already holds that name; using a conflict name"); - self.move_rename_remote(&uid, &parent, Some(&alt))?; + try_move(Some(&alt))?; self.adopt_drained_name(&uid, &alt); self.log_activity( ActivityKind::Rename, @@ -853,7 +883,7 @@ impl Core { ); alt } - Err(e) => return Err(e.into()), + Err(e) => return Err(e), } } // The destination folder is gone. Leaving the node in its current @@ -862,7 +892,7 @@ impl Core { // the user chose still applies there. Retrying the move could // only fail again — the folder is not coming back — and would // wedge the queue. - Err(e) if is_gone(&e) => { + Err(e) if is_gone(e.as_ref()) => { warn!(%uid, name, %parent, "move destination is gone; leaving the node where it is"); let landed = match self.drain_rename_in_place( op, @@ -885,7 +915,7 @@ impl Core { ); landed } - Err(e) => return Err(e.into()), + Err(e) => return Err(e), } }; self.db.delete_op(op.id)?; @@ -2699,6 +2729,29 @@ fn moved_elsewhere(meta: &RenameMeta, node: &Node, parent: &NodeUid, name: &str) !at(&meta.original_parent_uid, original_name) && !at(&parent.to_string(), name) } +/// A child can have a normal metadata record even when an ancestor is trashed. +/// Check both live parent chains before interpreting a refused move as an +/// access problem. Shared ancestors only need to be fetched once. +fn trashed_move_folder<'a>( + parents: impl IntoIterator, + mut fetch: impl FnMut(&NodeUid) -> Option, +) -> Option { + let mut seen = HashSet::new(); + for parent in parents { + let mut next = Some(parent.clone()); + while let Some(uid) = next.take() + && seen.insert(uid.clone()) + && let Some(node) = fetch(&uid) + { + if node.trashed { + return Some(node.name); + } + next = node.parent_uid; + } + } + None +} + /// The answer from Drive somewhere in `e`'s chain, if it got that far. fn proton_error<'e>(e: &'e (dyn std::error::Error + 'static)) -> Option<&'e ProtonError> { std::iter::successors(Some(e), |e| e.source()).find_map(|e| e.downcast_ref::()) @@ -2708,6 +2761,9 @@ fn proton_error<'e>(e: &'e (dyn std::error::Error + 'static)) -> Option<&'e Prot /// could not be reached, which says nothing; otherwise the issue Drive's answer /// is, or `Some(None)` for a failure that is not a refusal. fn refusal(e: &(dyn std::error::Error + 'static)) -> Option> { + if e.is::() { + return Some(Some(SyncIssue::Trashed)); + } let proton = proton_error(e)?; // A refused session refuses everything, so it says nothing about this // op either; the mount is offline for it (`Core::lost_link`). @@ -3115,6 +3171,31 @@ mod tests { } } + #[test] + fn a_refused_move_identifies_a_trashed_ancestor_on_either_side() { + let source = folder_node("source", Some("old")); + let destination = folder_node("destination", Some("new")); + let mut old = folder_node("old", None); + let mut new = folder_node("new", None); + let find = |old: &Node, new: &Node| { + trashed_move_folder([&source.uid, &destination.uid], |uid| { + [&source, &destination, old, new] + .into_iter() + .find(|node| node.uid == *uid) + .cloned() + }) + }; + old.trashed = true; + assert_eq!(find(&old, &new).as_deref(), Some("old")); + old.trashed = false; + new.trashed = true; + let error = TrashedMove(find(&old, &new).unwrap()); + assert_eq!(refusal(&error), Some(Some(SyncIssue::Trashed))); + assert!(error.to_string().contains("‘new’")); + new.trashed = false; + assert_eq!(find(&old, &new), None); + } + #[test] fn queued_cross_parent_rename_retains_viewer_source_authority_after_local_move() { use std::sync::atomic::{AtomicU64, Ordering}; diff --git a/crates/pdfs-fuse/src/sim/daemon.rs b/crates/pdfs-fuse/src/sim/daemon.rs index b897306..3a1cd9c 100644 --- a/crates/pdfs-fuse/src/sim/daemon.rs +++ b/crates/pdfs-fuse/src/sim/daemon.rs @@ -1917,6 +1917,68 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } + #[test] + #[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"] + fn a_move_blocked_by_trash_can_be_retried_after_restore() { + use pdfs_core::control::SyncIssue; + + let drive = FakeDrive::new(); + let dir = scratch("move-out-of-trash"); + let daemon = Daemon::start(&dir, drive.client(1, Faults::none())).unwrap(); + let mount = &daemon.mountpoint; + std::fs::create_dir_all(mount.join("source/nested")).unwrap(); + std::fs::create_dir(mount.join("destination")).unwrap(); + std::fs::write(mount.join("source/nested/wallpaper.jpg"), b"image").unwrap(); + assert!(wait_until(Duration::from_secs(30), || daemon.drained() + && drive.lookup("source/nested/wallpaper.jpg").is_some())); + let source = drive.lookup("source").unwrap(); + + let pause = |paused| Request::SetSyncPaused { + paused, + until: None, + }; + daemon.request(&pause(true)).unwrap(); + std::fs::rename( + mount.join("source/nested/wallpaper.jpg"), + mount.join("destination/wallpaper.jpg"), + ) + .unwrap(); + drive.device().trash("source"); + daemon.request(&pause(false)).unwrap(); + assert!(wait_until(Duration::from_secs(30), || daemon + .pending() + .is_ok_and(|ops| ops.iter().any(|op| op.issue + == Some(SyncIssue::Trashed) + && op + .last_error + .as_deref() + .is_some_and(|message| message.contains("‘source’")))))); + + daemon + .request(&Request::RetryPendingOp { id: None }) + .unwrap(); + assert!(wait_until(Duration::from_secs(30), || daemon + .pending() + .is_ok_and(|ops| ops.iter().any(|op| op.attempts >= 2)))); + daemon + .request(&Request::Restore { + uids: vec![source.to_string()], + }) + .unwrap(); + daemon + .request(&Request::RetryPendingOp { id: None }) + .unwrap(); + assert!(wait_until(Duration::from_secs(30), || daemon.drained() + && drive.lookup("destination/wallpaper.jpg").is_some())); + assert_eq!( + std::fs::read(mount.join("destination/wallpaper.jpg")).unwrap(), + b"image" + ); + + assert!(matches!(daemon.stop(), Ok(MountOutcome::Shutdown))); + let _ = std::fs::remove_dir_all(&dir); + } + #[test] #[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"] fn a_write_over_a_create_whose_read_back_failed_is_not_a_conflict() { diff --git a/crates/pdfs-fuse/src/sim/fake_drive.rs b/crates/pdfs-fuse/src/sim/fake_drive.rs index a9869e8..56a5c8d 100644 --- a/crates/pdfs-fuse/src/sim/fake_drive.rs +++ b/crates/pdfs-fuse/src/sim/fake_drive.rs @@ -160,6 +160,17 @@ impl Server { .is_some_and(|remote| remote.file.is_none() && !remote.trashed) } + fn in_trash(&self, uid: &NodeUid) -> bool { + let mut node = self.current(uid); + while let Some(remote) = node { + if remote.trashed { + return true; + } + node = remote.parent.as_ref().and_then(|uid| self.current(uid)); + } + false + } + fn is_below(&self, uid: &NodeUid, ancestor: &NodeUid) -> bool { let mut cursor = Some(uid.clone()); while let Some(at) = cursor { @@ -1037,6 +1048,12 @@ impl FakeClient { } let parent = new_parent.cloned().or(remote.parent.clone()); let name = new_name.unwrap_or(&remote.name).to_owned(); + if server.in_trash(uid) || parent.as_ref().is_some_and(|uid| server.in_trash(uid)) { + return Err(api( + ResponseCode::NotEnoughPermissions, + "an item involved in the move is in Trash", + )); + } if let Some(parent) = &parent { if !server.is_folder(parent) { return Err(api( diff --git a/crates/pdfs-fuse/src/sim/run.rs b/crates/pdfs-fuse/src/sim/run.rs index a63920d..3c42a78 100644 --- a/crates/pdfs-fuse/src/sim/run.rs +++ b/crates/pdfs-fuse/src/sim/run.rs @@ -112,6 +112,8 @@ struct Run { /// Run `profile` on `seed`. It answers a report of what went wrong, if /// anything did. pub(crate) fn run(seed: u64, profile: &'static Profile) -> Result<(), String> { + // The simulation suite runs serially. Discard logs left by earlier tests. + take_logged(); let dir = scratch(&format!("{}-{seed}", profile.name)); let mut rng = Rng::new(seed); let drive = FakeDrive::new(); @@ -137,6 +139,7 @@ pub(crate) fn run(seed: u64, profile: &'static Profile) -> Result<(), String> { let _ = daemon.stop(); } } + run.logged.extend(take_logged()); match outcome { Ok(()) => { let _ = std::fs::remove_dir_all(&dir); @@ -432,6 +435,7 @@ impl Run { fn report(&self, failure: &str, dir: &Path) -> String { let _ = std::fs::write(dir.join("steps.log"), self.log.join("\n") + "\n"); + let _ = std::fs::write(dir.join("daemon.log"), self.logged.join("\n") + "\n"); let tail = &self.log[self.log.len().saturating_sub(LOG_TAIL)..]; format!( "{} seed {} failed: {failure}\nreplay with PDFS_SIM_SEED={}; state kept in {}\nlast steps:\n{}", diff --git a/crates/pdfs-gui/src/app/pages/locations.rs b/crates/pdfs-gui/src/app/pages/locations.rs index 07a9edc..569f774 100644 --- a/crates/pdfs-gui/src/app/pages/locations.rs +++ b/crates/pdfs-gui/src/app/pages/locations.rs @@ -788,6 +788,9 @@ pub(crate) fn issue_text(issue: SyncIssue) -> String { SyncIssue::Access => gettext( "You can no longer change this on Proton Drive. Ask the owner for edit access, or export the file to keep your version.", ), + SyncIssue::Trashed => { + gettext("Restore the item or folder from Trash, then retry the move.") + } SyncIssue::Missing => gettext( "The folder this change belongs in is gone from Proton Drive. Export the file to keep your version.", ), diff --git a/docs/BUGS.md b/docs/BUGS.md index e58ea2e..7b8fb21 100644 --- a/docs/BUGS.md +++ b/docs/BUGS.md @@ -988,11 +988,16 @@ timing. **Where:** not located; the drain's conflict check in `crates/pdfs-fuse/src/drain.rs` is the first suspect -**Repro:** Only the CI run above. The last steps created `x/z/y/a.txt` (37 bytes), wrote 42 +**Repro:** The first CI failure created `x/z/y/a.txt` (37 bytes), wrote 42 bytes into it at offset 20, and brought every link up. Drive then held the file at its first 37 bytes, and the full content was in `x/z/y/a (sync-conflict …).txt`. No other client wrote to it. +On 2026-11-19, seed 1 of `one-client-echoes` showed the same symptom with delayed, +duplicated, and reordered events. A two-byte overwrite of `x/d` appeared only in a +conflict copy. Local replays passed. The simulation now retains its operation trace +and daemon logs on failure. [CI run](https://github.com/narrrl/proton-drive-linux/actions/runs/44427290348) + **Cause.** Not known. Nothing was lost, since the conflict copy holds the bytes, but the file conflicted with its own create. B183 and B184 found the same symptom after a lost create reply. diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 28f3bda..eb3ac26 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,13 +13,22 @@ scratch (user data in `staging/` and `recovery/` is never touched by this). ## [3.8.1] — 2026-11-19 -### Added +Schema: **45**. No database migration in this release. -- **Branding** icons updated, screenshots updated +### Changed + +- Refreshed the application icon and project artwork, and updated the documentation screenshots. ### Fixed -- **Cache Eviction** fixed an issue where it didn't scan past pinned files and now also reapplies the limit at startup. +- The cache skips pinned files when looking for space to reclaim and reapplies the configured + limit when the service starts. Pinned files and recovery data are preserved. +- Trashing a folder waits for queued moves out of it, including moves from nested subfolders. + If a move is blocked by an item or folder already in Trash, Sync and `pdfs sync issues` + identify what to restore before retrying. +- The system tray displays a warning icon when sync needs attention or the session has expired. +- Updated the Proton SDK to 0.12.1 so a fast local clock no longer causes Proton to reject + uploads of new files and photos. ## [3.8.0] — 2026-11-14 @@ -2363,6 +2372,7 @@ First stable release: FUSE files-on-demand mount, sync daemon under `proton-driv - The outstanding FUSE defects tracked in `docs/BUGS.md`, plus a truncate defect, validated by a new POSIX compliance suite for the filesystem. +[3.8.1]: https://github.com/narrrl/proton-drive-linux/releases/tag/v3.8.1 [3.5.0]: https://github.com/narrrl/proton-drive-linux/releases/tag/v3.5.0 [3.4.1]: https://github.com/narrrl/proton-drive-linux/releases/tag/v3.4.1 [3.4.0]: https://github.com/narrrl/proton-drive-linux/releases/tag/v3.4.0 diff --git a/docs/TESTING.md b/docs/TESTING.md index 7b8d849..dbfcb01 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -75,7 +75,8 @@ PDFS_SIM_SEED=7 RUST_LOG=pdfs_fuse=debug cargo test -p pdfs-fuse --lib \ | `PDFS_SIM_MEASURE` | Run `a_thousand_files_drain_as_fast_on_wifi_as_on_lan`, which times 1,000 files in 100 folders on a LAN and a Wi-Fi profile and prints the times | A failure is a seed that can be replayed, but the daemon uses real threads, so a race may need -several replays. In CI, the `simulation` job uploads the stacks of a hung run as an artifact. +several replays. In CI, the `simulation` job uploads the failed seed's steps and daemon logs, +along with thread stacks when the watchdog catches a hang. ## Acceptance suite