Skip to content

Commit 4e25f7d

Browse files
committed
FileNode/set fails to delete files (fixes #2485)
1 parent e944316 commit 4e25f7d

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

crates/common/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,19 @@ impl DavResources {
594594
})
595595
}
596596

597+
pub fn any_resource_path_by_id(&self, id: u32) -> Option<DavResourcePath<'_>> {
598+
self.resources
599+
.iter()
600+
.enumerate()
601+
.find(|(_, resource)| resource.document_id == id)
602+
.and_then(|(idx, resource)| {
603+
self.paths
604+
.iter()
605+
.find(|path| path.resource_idx == idx)
606+
.map(|path| DavResourcePath { path, resource })
607+
})
608+
}
609+
597610
pub fn subtree(&self, search_path: &str) -> impl Iterator<Item = DavResourcePath<'_>> {
598611
let prefix = format!("{search_path}/");
599612
self.paths.iter().filter_map(move |path| {

crates/jmap/src/file/set.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use jmap_proto::{
2121
};
2222
use jmap_tools::{JsonPointerItem, Key, Value};
2323
use store::{
24-
ValueKey, ahash::{AHashMap, AHashSet}, write::{AlignedBytes, Archive, BatchBuilder}
24+
ValueKey,
25+
ahash::{AHashMap, AHashSet},
26+
write::{AlignedBytes, Archive, BatchBuilder},
2527
};
2628
use trc::AddContext;
2729
use types::{
@@ -307,7 +309,7 @@ impl FileNodeSet for Server {
307309
'destroy: for id in will_destroy {
308310
let document_id = id.document_id();
309311

310-
let Some(file_node) = cache.container_resource_path_by_id(document_id) else {
312+
let Some(file_node) = cache.any_resource_path_by_id(document_id) else {
311313
response.not_destroyed.append(id, SetError::not_found());
312314
continue 'destroy;
313315
};

tests/src/jmap/files/node.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,18 @@ pub async fn test(params: &mut JMAPTest) {
297297
);
298298

299299
// Delete file and sub folders
300+
assert_eq!(
301+
account
302+
.jmap_destroy(
303+
MethodObject::FileNode,
304+
[&file_id],
305+
[("onDestroyRemoveChildren", true)],
306+
)
307+
.await
308+
.destroyed()
309+
.collect::<AHashSet<_>>(),
310+
[file_id.as_str(),].into_iter().collect::<AHashSet<_>>()
311+
);
300312
assert_eq!(
301313
account
302314
.jmap_destroy(
@@ -308,7 +320,6 @@ pub async fn test(params: &mut JMAPTest) {
308320
.destroyed()
309321
.collect::<AHashSet<_>>(),
310322
[
311-
file_id.as_str(),
312323
sub_sub_folder_id.as_str(),
313324
sub_folder_id.as_str(),
314325
root_folder_id.as_str()

0 commit comments

Comments
 (0)