Method TryDeleteAsync
TryDeleteAsync(FileId, CancellationToken)
Deletes an existing file, or a file added by this transaction, by its file ID if it exists, and reports whether it did.
Declaration
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 deleted by this transaction (or was added by this transaction and has been discarded); false if no such file exists. |
Remarks
This is the idempotent form of DeleteAsync(FileId, CancellationToken) for callers that are retrying or replaying work that may already have run. Nothing may be 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).
A file that another transaction has added and not committed yet exists as well: it is never reported as missing while that transaction is open, and its deletion is accepted, waited for or refused as described on DeleteAsync(FileId, CancellationToken). If the adding transaction rolls back while this method waits for it, there is no file any more and the method returns false.
Exceptions
| Type | Condition |
|---|---|
| RepoFileBusyException | Another transaction is adding the file and has not finished, and the implementation does not accept the deletion of such a file. Nothing has been recorded, and the deletion can be made again once that transaction has finished. |
| OperationCanceledException | The token was cancelled before the deletion had been recorded. Nothing has been recorded. |
| ObjectDisposedException | The transaction has been disposed. |