Details
-
Improvement
-
Resolution: Unresolved
-
Minor - P4
-
None
-
None
-
None
-
None
-
Go Drivers
Description
Context
Bucket.Delete and DeleteContext return an ErrFileNotFound error when the file document does not exist but chunks may have been deleted.
It should check the chunk error and only return ErrFileNotFound if no file or chunk documents were found.
Why do this?
After a failed upload you can have chunks with no file document in mongodb using gridfs. The Delete methods should be able to clean this up without erroring. Also returning an error when Delete did in fact delete/fully cleanup a file doesn't make any sense.
Definition of done
What must be done to consider the task complete?
A gridfs upload can fail and leave chunks in the chunks collection without a corresponding file document. If you call Delete or DeleteContext using the file id of these chunks then an error is returned that the file doesn't exist. It should return nil instead when these existing chunks are cleaned up. ErrFileNotFound should only be returned if both the file document and chunks do not exist.
Pitfalls
Existing code could potentially be relying on this and require a version bump. However I believe it's unlikely as most code probably ignores the error from delete when used for cleanup after a failed file upload.
See https://github.com/mongodb/mongo-go-driver/blob/v1/mongo/gridfs/bucket.go#L277
The chunks error is ignored. This should be checked and if nil/deleted chunk documents and the file error is ErrFileNotFound then no error should be returned.