Skip to content

Commit

Permalink
Properly sync file_path deletion when deleting directories
Browse files Browse the repository at this point in the history
  • Loading branch information
fogodev committed Oct 24, 2024
1 parent e4e6a11 commit 538af49
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions core/src/location/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,9 @@ pub async fn delete_directory(
library: &Library,
location_id: location::id::Type,
parent_iso_file_path: Option<&IsolatedFilePathData<'_>>,
) -> Result<(), QueryError> {
) -> Result<(), sd_core_sync::Error> {
let Library { db, .. } = library;

// This is NOT sync-compatible!
// Sync requires having sync ids available.
let children_params = sd_utils::chain_optional_iter(
[file_path::location_id::equals(Some(location_id))],
[parent_iso_file_path.and_then(|parent| {
Expand All @@ -899,7 +897,39 @@ pub async fn delete_directory(
})],
);

db.file_path().delete_many(children_params).exec().await?;
let pub_ids = library
.db
.file_path()
.find_many(children_params.clone())
.select(file_path::select!({ pub_id }))
.exec()
.await?
.into_iter()
.map(|fp| fp.pub_id)
.collect::<Vec<_>>();

if pub_ids.is_empty() {
debug!("No file paths to delete");
return Ok(());
}

library
.sync
.write_ops(
&library.db,
(
pub_ids
.into_iter()
.map(|pub_id| {
library
.sync
.shared_delete(prisma_sync::file_path::SyncId { pub_id })
})
.collect(),
db.file_path().delete_many(children_params),
),
)
.await?;

// library.orphan_remover.invoke().await;

Expand Down

0 comments on commit 538af49

Please sign in to comment.