Method TryDeleteAsync
TryDeleteAsync(FileId, CancellationToken)
Deletes an existing or tentatively added file from the repository by its file ID if it exists, and reports whether it did.
Declaration
public Task<bool> TryDeleteAsync(FileId fileId, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| FileId | fileId | The ID of the file to delete. |
| CancellationToken | cancellationToken | A cancellation token that cancels the operation. |
Returns
| Type | Description |
|---|---|
| Task<bool> | true if the file existed and is now scheduled for deletion by this transaction (or was added by this transaction and has been discarded); false if no such file exists. |
Implements
Remarks
This is the idempotent form of DeleteAsync(FileId, CancellationToken) for callers that are retrying or replaying work that may already have run, such as a queue of deletions replayed after a crash. Nothing is written to the repository when false is returned.
A file that another transaction has deleted exists until its deletion has been carried out, so this method returns true for a file whose deletion has committed and is pending cleanup, and the deletions converge as described on DeleteAsync(FileId, CancellationToken).
Prefer DeleteAsync(FileId, CancellationToken) when the application believes the file exists: a file that is unexpectedly missing usually indicates an application bug or a missing referenced file, and it should surface rather than be ignored.
A file that another transaction has added and not committed yet is not reported as missing while that transaction is open: this method waits for the file's indeterminate marker as DeleteAsync(FileId, CancellationToken) does, returns true if the add was committed in that time and false if it was rolled back, and throws a RepoFileBusyException if the marker is still in use when the wait is over.
Exceptions
| Type | Condition |
|---|---|
| RepoFileBusyException | The file's indeterminate marker was still in use when the wait for it was over, which normally means that another transaction is adding the file and has not committed or rolled back yet. Nothing has been recorded. |
| OperationCanceledException | The token was cancelled while the call waited: for another call on this transaction, or for the file's indeterminate marker. Nothing has been recorded. |