From f3769b4e59afec4f6593d720c0f86bbc875e206a Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Thu, 30 Jul 2026 18:26:17 +0200 Subject: [PATCH] move note files to the trash folder in move_note_to_trash --- application/backend/src/backend.rs | 21 ++++++++++++++++++++- application/note/src/file.rs | 4 ---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/application/backend/src/backend.rs b/application/backend/src/backend.rs index 1e65654..edde6d5 100644 --- a/application/backend/src/backend.rs +++ b/application/backend/src/backend.rs @@ -775,6 +775,7 @@ impl BackendHandle { let trash_id = BackendHandle::get_trash_id(&backend.db, profile_id) .await? .ok_or_else(|| DbErr::Custom("Trash not found".into()))?; + let path = get_note_storage_path(&backend.db, note_id).await?; let result = note::Entity::update_many() .filter(note::Column::NoteId.eq(note_id)) @@ -782,6 +783,24 @@ impl BackendHandle { .exec(&backend.db).await?; if result.rows_affected == 1 { + if let Some(path) = path { + let note_path = Path::new(&path); + let trash_path = get_collection_storage_path(&backend.db, trash_id) + .await? + .ok_or(DbErr::Custom("Trash local path not found".into()))?; + // Even though the nodename probably already has a random suffix, we just + // add another random suffix, to make sure the trash filename is unique. + // It does not need to look pretty in the trash folder + let note_name = note_path.file_name().unwrap_or(std::ffi::OsStr::new("")).to_str().unwrap_or("").to_string(); + let trashed_nodename = randomize_nodename(note_name.as_str()); + let trashed_path = PathBuf::from(trash_path).join(trashed_nodename); + let rename_result = tokio::fs::rename(path, &trashed_path).await; + if let Err(e) = rename_result { + // TODO: revert db previous update + return Err(DbErr::Custom(format!("rename failed: {}", e))); + } + } + Ok(()) } else { Err(DbErr::Custom("unexpected number of affected rows".into())) @@ -798,7 +817,7 @@ impl BackendHandle { .filter(collection::Column::ProfileId.eq(profile_id)) .select_only() .column(collection::Column::CollectionId) - .into_tuple::<(i32)>() + .into_tuple::() .one(db).await } } diff --git a/application/note/src/file.rs b/application/note/src/file.rs index d3f0779..a84be06 100644 --- a/application/note/src/file.rs +++ b/application/note/src/file.rs @@ -145,10 +145,6 @@ impl FileNote { return; } - let Some(doc) = self.doc.get_doc() else { - return; - }; - // The path should exist, because query_local_path is called when creating this object if let Some(path) = &self.local_path { println!("open file: {}", path.to_string_lossy()); -- 2.52.0