Method DeleteAsync
DeleteAsync(FileId, CancellationToken)
Deletes an existing file, or a file added by this transaction, by its file ID.
Declaration
Task DeleteAsync(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 |
Remarks
Use this method when the application believes the file exists, so that a mismatch surfaces as an exception. To delete a file that may already be gone, use TryDeleteAsync(FileId, CancellationToken) instead.
Deleting a file that this transaction added discards the add. Deleting a file that this transaction has already deleted or discarded does nothing. The file stays readable until the transaction commits; afterwards, whether it can still be read until a cleanup pass depends on DeleteMode.
Deleting a file that another transaction has also deleted succeeds, including when that deletion has committed and the file is pending cleanup. Implementations must make the deletions converge in every delete mode, whichever kind of transaction made them. Only a file that is gone, or never existed, throws.
A file that another transaction has added and not committed yet exists. An implementation either accepts its deletion, which then wins (once this transaction has committed, the file is deleted whatever the adding transaction does afterwards, and that transaction's commit succeeds without bringing the file back), or does not accept it while the adding transaction is open. In that case it may wait briefly for that transaction to finish, because it normally does so within milliseconds, and then makes the deletion as if the call had been made at that moment: the file is deleted if its add was committed, and not found if it was rolled back. If the adding transaction is still open when the wait is over, it refuses the deletion with a RepoFileBusyException, having recorded nothing; this transaction stays usable, and the deletion can be made again. A deletion that has committed is never undone by the add.
Exceptions
| Type | Condition |
|---|---|
| RepoFileNotFoundException | The file was not found in the repository: it never existed, or its deletion has already been carried out. |
| 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. |