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))
.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()))
.filter(collection::Column::ProfileId.eq(profile_id))
.select_only()
.column(collection::Column::CollectionId)
- .into_tuple::<(i32)>()
+ .into_tuple::<i32>()
.one(db).await
}
}
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());