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 its deletion is now recorded 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 is recorded 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).
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. |
| InvalidOperationException | The transaction has been staged or rolled back. |
| ObjectDisposedException | The transaction has been disposed. |