Address trash moves and deletes by path, not fileid

Trashing or emptying the trash failed on every scanned image with
"operation unsupported by this backend: fetch by fileid requires a
path".

RemoteId::Stable(oc:fileid) is an identity — it answers whether a file
is the same one after a move, and keys the thumbnail shards. It is not
an address: WebDAV exposes no fileid-addressable endpoint, so the
Nextcloud backend serves get/delete/move_to by path and rejects a bare
Stable. Both trash workers preferred the fileid whenever the catalog
knew one, so the unreachable Path fallback was the only arm that would
have worked, and the failure hit every properly-scanned image rather
than some edge case.

Address by path at both sites, and keep the fileid for what it is for:
the identity MOVE preserves, and the key the thumbnail cleanup uses.

Move::file_id was documented as "the id the MOVE addresses", which is
the wrong claim that seeded this; corrected, along with a note on
RemoteId itself so the distinction is stated where the type is defined.

Only the backend rejection was covered by a test. Added the positive
case, since that contract is what the call sites now depend on. The
workers build their own NextcloudBackend, so no test can reach the
call sites directly — closing that would mean injecting the backend,
which is left alone here.

Verified by build and test; not exercised against a live server.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 21:39:35 +02:00
co-authored by Claude Opus 5
parent 9a24623e35
commit b4c1645c7a
3 changed files with 52 additions and 14 deletions
+28 -14
View File
@@ -65,14 +65,20 @@ pub enum Direction {
/// One image to move, resolved before the worker starts.
///
/// Carries the id the `MOVE` addresses and the destination path, so the worker
/// needs no catalog access to do its half — the catalog is not `Send`, and the
/// worker owns a separate connection only for the write-back.
/// Carries the paths the `MOVE` runs between, so the worker needs no catalog
/// access to do its half — the catalog is not `Send`, and the worker owns a
/// separate connection only for the write-back.
#[derive(Debug, Clone)]
pub struct Move {
pub image_id: ImageId,
/// `oc:fileid` where known, else the path. A stable id survives the move and
/// keeps the thumbnail and sidecar mapping attached.
/// `oc:fileid` where the catalog knows one — the identity `MOVE` preserves,
/// which is what keeps the thumbnail and sidecar mapping attached across a
/// trash and restore.
///
/// Not how the file is addressed: the `MOVE` goes from `from` to `to`,
/// because WebDAV exposes no fileid-addressable endpoint and the backend
/// rejects a bare `RemoteId::Stable`. Carried so the plan records the
/// identity it expects to survive.
pub file_id: Option<u64>,
pub from: String,
pub to: String,
@@ -199,13 +205,22 @@ pub fn spawn_move(
let mut failed: Vec<String> = Vec::new();
for (i, mv) in moves.iter().enumerate() {
let id = match mv.file_id {
Some(f) => RemoteId::Stable(f),
None => RemoteId::Path(RemotePath::new(&mv.from)),
};
// Addressed by path, not by `mv.file_id`: WebDAV has no
// fileid-addressable endpoint, so a `RemoteId::Stable` here is
// rejected by the backend. The fileid is an identity that the
// MOVE preserves, not a way to name the source.
let id = RemoteId::Path(RemotePath::new(&mv.from));
match backend.move_to(&id, &RemotePath::new(&mv.to)).await {
Ok(()) => succeeded.push((mv.image_id, mv.to.clone())),
Ok(()) => {
// The fileid is logged, not sent: if a restore later
// shows a missing thumbnail, this is the record of which
// identity the MOVE was supposed to carry across.
if let Some(f) = mv.file_id {
log::debug!("moved {} to {} as fileid {f}", mv.from, mv.to);
}
succeeded.push((mv.image_id, mv.to.clone()));
}
Err(e) => {
// Named by file, not by id: the user recognises the
// filename and cannot do anything with a row number.
@@ -307,10 +322,9 @@ pub fn spawn_purge(
let mut failed: Vec<String> = Vec::new();
for (i, (image, file_id, path)) in paths.iter().enumerate() {
let id = match file_id {
Some(f) => RemoteId::Stable(*f),
None => RemoteId::Path(RemotePath::new(path)),
};
// By path — see `spawn_move`. `file_id` still matters below, as
// the key the thumbnail shards are stored under.
let id = RemoteId::Path(RemotePath::new(path));
match backend.delete(&id, None).await {
Ok(()) => {