Method DeleteAsync
DeleteAsync(FileId, CancellationToken)
Deletes an existing or tentatively added file from the repository by its file ID.
Declaration
public 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 |
Implements
Remarks
Use this method when the application believes the file exists, so that a mismatch (a stale reference, or a referenced file that is missing) surfaces as an exception. To delete a file that may already be gone, for example when retrying or replaying work that may already have run, use TryDeleteAsync(FileId, CancellationToken) instead.
Deleting a file that was added by this transaction 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: the deletions converge in every DeleteMode, 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 cannot be deleted while that transaction is open, because it holds the file's indeterminate marker, which this deletion is recorded in. The adding transaction normally finishes within milliseconds, so this method waits for the marker, for up to half a second, and then makes the deletion as if it had been called at that moment: the file is deleted if its add was committed, and not found if it was rolled back. If the marker is still in use when the wait is over, the method throws a RepoFileBusyException. Nothing has been recorded then, and the transaction stays usable: the deletion can be made again, and succeeds once the adding transaction has committed. The wait cannot end if the adding transaction is one that the caller itself has open, which is why it is short. A FileRepoStagedTransaction on a repository with delete journals accepts such a deletion instead.
Exceptions
| Type | Condition |
|---|---|
| RepoFileNotFoundException | The file was not found in the repository: it never existed, or its deletion has already been carried out. |
| 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. |