DM-25818 we changed datastore.put such that it overwrites existing files. This assumes that registry knows what is going on.
In the ticket the possibility was raised that a dataset could be trashed (which does not delete the file) and another file with the same dataId be put simultaneously. These would share the same filename but different dataset_id and results in the possibility of one process writing the new file just before emptyTrash is called deleting what it thinks is the old file.
A suggestion was to include the dataset_id in the file name.