[CDRIVER-387] add mongoc_gridfs_file_remove() helper Created: 02/Jul/14  Updated: 03/May/17  Resolved: 07/Jul/14

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: TBD

Type: Improvement Priority: Minor - P4
Reporter: Christian Hergert Assignee: Christian Hergert
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

It would be nice to have a helper to make it easier to remove a particular gridfs file. This should remove the gridfs file and any chunks associated with it.

Something like:

if (!mongoc_gridfs_file_remove (file, &error)) {
   fprintf (stderr, "%s\n", error.message);
}
mongoc_gridfs_destroy (file);



 Comments   
Comment by Christian Hergert [ 07/Jul/14 ]

https://github.com/mongodb/mongo-c-driver/commit/d2cc0bc7a505cdcb0da79c8962cc50b04e2f771a contains a fix for this.

I decided to not have it perform the additional destroy() on the file structure as per previous comment. Feel free to add yourself a macro like such if you want a fire and forget style call.

#define mongoc_gridfs_file_remove_and_destroy(f) do { mongoc_gridfs_file_remove(f,NULL); mongoc_gridfs_file_destroy(f); } while (0)

Comment by Christian Hergert [ 02/Jul/14 ]

The problem is that it would be inconsistent with the memory management of all of the other functions that are destructive. Especially since the operation can fail, and therefore retry would be impossible without reacquiring the mongoc_gridfs_file_t.

Comment by Frank J. Lhota [ 02/Jul/14 ]

IMO the function mongoc_gridfs_file_remove(file) should, as its final operation, destroy the file parameter passed to it. After calling this function, the mongoc_gridfs_file_t object passed to it no longer corresponds to a file and chunks in the GRID file system, so it should not be used for any other GRID operation.

Generated at Wed Feb 07 21:09:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.