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
The file must exist when this method is called. The deletion is recorded by the transaction and made durable by StageAsync(CancellationToken); an implementation does not have to write anything before then.
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.
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: it may wait briefly for that transaction to finish, and refuses the deletion with a RepoFileBusyException if it is still open then, as described on DeleteAsync(FileId, CancellationToken). It does so in this method or in StageAsync(CancellationToken), which is before the application commits its database. 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. |
| InvalidOperationException | The transaction has been staged or rolled back. |
| ObjectDisposedException | The transaction has been disposed. |