Skip to content

Commit

Permalink
Merge pull request #405 from djmitche/issue383
Browse files Browse the repository at this point in the history
Make `Replica::delete_task` public
  • Loading branch information
djmitche authored Jun 21, 2024
2 parents 4724b79 + c64db82 commit b05435d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
File renamed without changes.
24 changes: 24 additions & 0 deletions lib/src/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,30 @@ pub unsafe extern "C" fn tc_replica_import_task_with_uuid(
)
}

#[ffizz_header::item]
#[ffizz(order = 902)]
/// Delete a task. The task must exist. Note that this is different from setting status to
/// Deleted; this is the final purge of the task.
///
/// ```c
/// EXTERN_C struct TCTask *tc_replica_delete_task(struct TCReplica *rep, struct TCUuid tcuuid);
/// ```
#[no_mangle]
pub unsafe extern "C" fn tc_replica_delete_task(rep: *mut TCReplica, tcuuid: TCUuid) -> TCResult {
wrap(
rep,
|rep| {
// SAFETY:
// - tcuuid is a valid TCUuid (all bytes are valid)
// - tcuuid is Copy so ownership doesn't matter
let uuid = unsafe { TCUuid::val_from_arg(tcuuid) };
rep.delete_task(uuid)?;
Ok(TCResult::Ok)
},
TCResult::Error,
)
}

#[ffizz_header::item]
#[ffizz(order = 902)]
/// Synchronize this replica with a server.
Expand Down
4 changes: 4 additions & 0 deletions lib/taskchampion.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ EXTERN_C struct TCTaskList tc_replica_all_tasks(struct TCReplica *rep);
// there are no operations that can be done.
EXTERN_C TCResult tc_replica_commit_undo_ops(struct TCReplica *rep, TCReplicaOpList tc_undo_ops, int32_t *undone_out);

// Delete a task. The task must exist. Note that this is different from setting status to
// Deleted; this is the final purge of the task.
EXTERN_C struct TCTask *tc_replica_delete_task(struct TCReplica *rep, struct TCUuid tcuuid);

// Get the latest error for a replica, or a string with NULL ptr if no error exists. Subsequent
// calls to this function will return NULL. The rep pointer must not be NULL. The caller must
// free the returned string.
Expand Down
10 changes: 7 additions & 3 deletions taskchampion/src/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@ impl Replica {
}

/// Delete a task. The task must exist. Note that this is different from setting status to
/// Deleted; this is the final purge of the task. This is not a public method as deletion
/// should only occur through expiration.
fn delete_task(&mut self, uuid: Uuid) -> Result<()> {
/// Deleted; this is the final purge of the task.
///
/// Deletion may interact poorly with modifications to the same task on other replicas. For
/// example, if a task is deleted on replica 1 and its description modified on replica 1, then
/// after both replicas have fully synced, the resulting task will only have a `description`
/// property.
pub fn delete_task(&mut self, uuid: Uuid) -> Result<()> {
self.add_undo_point(false)?;
self.taskdb.apply(SyncOp::Delete { uuid })?;
trace!("task {} deleted", uuid);
Expand Down

0 comments on commit b05435d

Please sign in to comment.