]> uap-core.de Git - note.git/commitdiff
move note files to the trash folder in move_note_to_trash
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 30 Jul 2026 16:26:17 +0000 (18:26 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 30 Jul 2026 16:26:17 +0000 (18:26 +0200)
application/backend/src/backend.rs
application/note/src/file.rs

index 1e656541034a592950f3155b927af95bef8eb9cf..edde6d53bc6f292eccedf9a14a13ddd5ac72e4c3 100644 (file)
@@ -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::<i32>()
             .one(db).await
     }
 }
index d3f077943d4d1872fc59fc670aeca8225bf1103e..a84be063968bd81f9cb858cdafd218d602d796ed 100644 (file)
@@ -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());