FileNode/set fails to delete files (fixes #2485)
This commit is contained in:
@@ -594,6 +594,19 @@ impl DavResources {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn any_resource_path_by_id(&self, id: u32) -> Option<DavResourcePath<'_>> {
|
||||
self.resources
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, resource)| resource.document_id == id)
|
||||
.and_then(|(idx, resource)| {
|
||||
self.paths
|
||||
.iter()
|
||||
.find(|path| path.resource_idx == idx)
|
||||
.map(|path| DavResourcePath { path, resource })
|
||||
})
|
||||
}
|
||||
|
||||
pub fn subtree(&self, search_path: &str) -> impl Iterator<Item = DavResourcePath<'_>> {
|
||||
let prefix = format!("{search_path}/");
|
||||
self.paths.iter().filter_map(move |path| {
|
||||
|
||||
@@ -21,7 +21,9 @@ use jmap_proto::{
|
||||
};
|
||||
use jmap_tools::{JsonPointerItem, Key, Value};
|
||||
use store::{
|
||||
ValueKey, ahash::{AHashMap, AHashSet}, write::{AlignedBytes, Archive, BatchBuilder}
|
||||
ValueKey,
|
||||
ahash::{AHashMap, AHashSet},
|
||||
write::{AlignedBytes, Archive, BatchBuilder},
|
||||
};
|
||||
use trc::AddContext;
|
||||
use types::{
|
||||
@@ -307,7 +309,7 @@ impl FileNodeSet for Server {
|
||||
'destroy: for id in will_destroy {
|
||||
let document_id = id.document_id();
|
||||
|
||||
let Some(file_node) = cache.container_resource_path_by_id(document_id) else {
|
||||
let Some(file_node) = cache.any_resource_path_by_id(document_id) else {
|
||||
response.not_destroyed.append(id, SetError::not_found());
|
||||
continue 'destroy;
|
||||
};
|
||||
|
||||
@@ -297,6 +297,18 @@ pub async fn test(params: &mut JMAPTest) {
|
||||
);
|
||||
|
||||
// Delete file and sub folders
|
||||
assert_eq!(
|
||||
account
|
||||
.jmap_destroy(
|
||||
MethodObject::FileNode,
|
||||
[&file_id],
|
||||
[("onDestroyRemoveChildren", true)],
|
||||
)
|
||||
.await
|
||||
.destroyed()
|
||||
.collect::<AHashSet<_>>(),
|
||||
[file_id.as_str(),].into_iter().collect::<AHashSet<_>>()
|
||||
);
|
||||
assert_eq!(
|
||||
account
|
||||
.jmap_destroy(
|
||||
@@ -308,7 +320,6 @@ pub async fn test(params: &mut JMAPTest) {
|
||||
.destroyed()
|
||||
.collect::<AHashSet<_>>(),
|
||||
[
|
||||
file_id.as_str(),
|
||||
sub_sub_folder_id.as_str(),
|
||||
sub_folder_id.as_str(),
|
||||
root_folder_id.as_str()
|
||||
|
||||
Reference in New Issue
Block a user