Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDRIVER-5950 remove deprecated GridFS API #1961

Merged
merged 3 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ Unreleased (2.0.0)
* Deprecated API for `mongoc_database_t` is removed:
* `mongoc_database_find_collections` is removed. Use `mongoc_database_find_collections_with_opts` instead.
* `mongoc_database_get_collection_names` is removed. Use `mongoc_database_get_collection_names_with_opts` instead.
* Deprecated GridFS API has been removed:
* `mongoc_gridfs_find` is removed. Use `mongoc_gridfs_find_with_opts` instead.
* `mongoc_gridfs_find_one` is removed. Use `mongoc_gridfs_find_one_with_opts` instead.

### Forwarding headers (`#include <bson.h>` and `#include <mongoc.h>`)

Expand Down
6 changes: 0 additions & 6 deletions build/generate-future-functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,6 @@
param("size_t", "min_bytes"),
param("uint32_t", "timeout_msec")]),

future_function("mongoc_gridfs_file_ptr",
"mongoc_gridfs_find_one",
[param("mongoc_gridfs_ptr", "gridfs"),
param("const_bson_ptr", "query"),
param("bson_error_ptr", "error")]),

future_function("bool",
"mongoc_gridfs_file_remove",
[param("mongoc_gridfs_file_ptr", "file"),
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/doc/mongoc_gridfs_file_list_t.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Example
mongoc_gridfs_file_list_t *list;
mongoc_gridfs_file_t *file;

list = mongoc_gridfs_find (gridfs, query);
list = mongoc_gridfs_find_with_opts (gridfs, query, NULL);

while ((file = mongoc_gridfs_file_list_next (list))) {
do_something (file);
Expand Down
37 changes: 0 additions & 37 deletions src/libmongoc/doc/mongoc_gridfs_find.rst

This file was deleted.

44 changes: 0 additions & 44 deletions src/libmongoc/doc/mongoc_gridfs_find_one.rst

This file was deleted.

2 changes: 0 additions & 2 deletions src/libmongoc/doc/mongoc_gridfs_t.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ Example
mongoc_gridfs_create_file_from_stream
mongoc_gridfs_destroy
mongoc_gridfs_drop
mongoc_gridfs_find
mongoc_gridfs_find_one
mongoc_gridfs_find_one_by_filename
mongoc_gridfs_find_one_with_opts
mongoc_gridfs_find_with_opts
Expand Down
31 changes: 0 additions & 31 deletions src/libmongoc/src/mongoc/mongoc-gridfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,37 +174,6 @@ mongoc_gridfs_destroy (mongoc_gridfs_t *gridfs)
}


/** find all matching gridfs files */
mongoc_gridfs_file_list_t *
mongoc_gridfs_find (mongoc_gridfs_t *gridfs, const bson_t *query)
{
return _mongoc_gridfs_file_list_new (gridfs, query, 0);
}


/** find a single gridfs file */
mongoc_gridfs_file_t *
mongoc_gridfs_find_one (mongoc_gridfs_t *gridfs, const bson_t *query, bson_error_t *error)
{
mongoc_gridfs_file_list_t *list;
mongoc_gridfs_file_t *file;

ENTRY;

list = _mongoc_gridfs_file_list_new (gridfs, query, 1);

file = mongoc_gridfs_file_list_next (list);
if (!mongoc_gridfs_file_list_error (list, error) && error) {
/* no error, but an error out-pointer was provided - clear it */
memset (error, 0, sizeof (*error));
}

mongoc_gridfs_file_list_destroy (list);

RETURN (file);
}


/** find all matching gridfs files */
mongoc_gridfs_file_list_t *
mongoc_gridfs_find_with_opts (mongoc_gridfs_t *gridfs, const bson_t *filter, const bson_t *opts)
Expand Down
9 changes: 0 additions & 9 deletions src/libmongoc/src/mongoc/mongoc-gridfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ mongoc_gridfs_create_file_from_stream (mongoc_gridfs_t *gridfs, mongoc_stream_t
MONGOC_EXPORT (mongoc_gridfs_file_t *)
mongoc_gridfs_create_file (mongoc_gridfs_t *gridfs, mongoc_gridfs_file_opt_t *opt) BSON_GNUC_WARN_UNUSED_RESULT;

BSON_DEPRECATED_FOR (mongoc_gridfs_find_with_opts)
MONGOC_EXPORT (mongoc_gridfs_file_list_t *) mongoc_gridfs_find (mongoc_gridfs_t *gridfs, const bson_t *query)
BSON_GNUC_WARN_UNUSED_RESULT;

BSON_DEPRECATED_FOR (mongoc_gridfs_find_one_with_opts)
MONGOC_EXPORT (mongoc_gridfs_file_t *)
mongoc_gridfs_find_one (mongoc_gridfs_t *gridfs, const bson_t *query, bson_error_t *error)
BSON_GNUC_WARN_UNUSED_RESULT;

MONGOC_EXPORT (mongoc_gridfs_file_list_t *)
mongoc_gridfs_find_with_opts (mongoc_gridfs_t *gridfs, const bson_t *filter, const bson_t *opts)
BSON_GNUC_WARN_UNUSED_RESULT;
Expand Down
43 changes: 0 additions & 43 deletions src/libmongoc/tests/mock_server/future-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,27 +851,6 @@ BSON_THREAD_FUN (background_mongoc_gridfs_file_readv, data)
BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_gridfs_find_one, data)
{
future_t *future = (future_t *) data;
future_value_t return_value;

return_value.type = future_value_mongoc_gridfs_file_ptr_type;

future_value_set_mongoc_gridfs_file_ptr (
&return_value,
mongoc_gridfs_find_one (
future_value_get_mongoc_gridfs_ptr (future_get_param (future, 0)),
future_value_get_const_bson_ptr (future_get_param (future, 1)),
future_value_get_bson_error_ptr (future_get_param (future, 2))
));

future_resolve (future, return_value);

BSON_THREAD_RETURN;
}

static
BSON_THREAD_FUN (background_mongoc_gridfs_file_remove, data)
{
Expand Down Expand Up @@ -2304,28 +2283,6 @@ future_gridfs_file_readv (
return future;
}

future_t *
future_gridfs_find_one (
mongoc_gridfs_ptr gridfs,
const_bson_ptr query,
bson_error_ptr error)
{
future_t *future = future_new (future_value_mongoc_gridfs_file_ptr_type,
3);

future_value_set_mongoc_gridfs_ptr (
future_get_param (future, 0), gridfs);

future_value_set_const_bson_ptr (
future_get_param (future, 1), query);

future_value_set_bson_error_ptr (
future_get_param (future, 2), error);

future_start (future, background_mongoc_gridfs_find_one);
return future;
}

future_t *
future_gridfs_file_remove (
mongoc_gridfs_file_ptr file,
Expand Down
9 changes: 0 additions & 9 deletions src/libmongoc/tests/mock_server/future-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,6 @@ future_gridfs_file_readv (
);


future_t *
future_gridfs_find_one (

mongoc_gridfs_ptr gridfs,
const_bson_ptr query,
bson_error_ptr error
);


future_t *
future_gridfs_file_remove (

Expand Down
26 changes: 13 additions & 13 deletions src/libmongoc/tests/test-mongoc-gridfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ test_list (void)
mongoc_client_t *client;
bson_error_t error;
mongoc_gridfs_file_list_t *list;
bson_t query, child;
bson_t query, opts, child;
char buf[100];
int i = 0;

Expand All @@ -287,14 +287,14 @@ test_list (void)
prep_files (gridfs);

bson_init (&query);
bson_append_document_begin (&query, "$orderby", -1, &child);
bson_init (&opts);
bson_append_document_begin (&opts, "sort", -1, &child);
bson_append_int32 (&child, "filename", -1, 1);
bson_append_document_end (&query, &child);
bson_append_document_begin (&query, "$query", -1, &child);
bson_append_document_end (&query, &child);
bson_append_document_end (&opts, &child);

list = mongoc_gridfs_find (gridfs, &query);
list = mongoc_gridfs_find_with_opts (gridfs, &query, NULL);

bson_destroy (&opts);
bson_destroy (&query);

i = 0;
Expand All @@ -310,7 +310,7 @@ test_list (void)

bson_init (&query);
bson_append_utf8 (&query, "filename", -1, "file.1", -1);
ASSERT_OR_PRINT (file = mongoc_gridfs_find_one (gridfs, &query, &error), error);
ASSERT_OR_PRINT (file = mongoc_gridfs_find_one_with_opts (gridfs, &query, NULL, &error), error);
bson_destroy (&query);

ASSERT_CMPINT (strcmp (mongoc_gridfs_file_get_filename (file), "file.1"), ==, 0);
Expand Down Expand Up @@ -494,7 +494,7 @@ test_properties (void)

ASSERT (mongoc_collection_insert_one (mongoc_gridfs_get_files (gridfs), doc_in, NULL, NULL, NULL));

list = mongoc_gridfs_find (gridfs, &query);
list = mongoc_gridfs_find_with_opts (gridfs, &query, NULL);
file = mongoc_gridfs_file_list_next (list);
file_id = mongoc_gridfs_file_get_id (file);
ASSERT (file_id);
Expand Down Expand Up @@ -859,7 +859,7 @@ test_write_past_end (void)
ASSERT (mlib_cmp (expected_chunks, ==, cnt));

mongoc_gridfs_file_destroy (file);
file = mongoc_gridfs_find_one (gridfs, tmp_bson (NULL), &error);
file = mongoc_gridfs_find_one_with_opts (gridfs, tmp_bson (NULL), NULL, &error);
ASSERT_OR_PRINT (file, error);

BSON_ASSERT (mlib_in_range (size_t, delta + len));
Expand Down Expand Up @@ -1021,7 +1021,7 @@ test_long_seek (void *ctx)
/* new file handle */
mongoc_gridfs_file_save (file);
mongoc_gridfs_file_destroy (file);
file = mongoc_gridfs_find_one (gridfs, tmp_bson ("{'filename': 'filename'}"), &error);
file = mongoc_gridfs_find_one_with_opts (gridfs, tmp_bson ("{'filename': 'filename'}"), NULL, &error);

ASSERT_OR_PRINT (file, error);

Expand Down Expand Up @@ -1306,7 +1306,7 @@ test_set_id (void)
/* if we find a file with new id, then file_set_id worked */
ASSERT_OR_PRINT (mongoc_gridfs_file_set_id (file, &id, &error), error);
ASSERT (mongoc_gridfs_file_save (file));
result = mongoc_gridfs_find_one (gridfs, query, &error);
result = mongoc_gridfs_find_one_with_opts (gridfs, query, NULL, &error);
ASSERT_OR_PRINT (result, error);

mongoc_gridfs_file_destroy (result);
Expand Down Expand Up @@ -1352,7 +1352,7 @@ test_inherit_client_config (void)
gridfs = _get_gridfs (server, client, MONGOC_QUERY_NONE);

/* test read prefs and read concern */
future = future_gridfs_find_one (gridfs, tmp_bson ("{}"), &error);
future = future_gridfs_find_one_with_opts (gridfs, tmp_bson ("{}"), NULL, &error);
request = mock_server_receives_msg (server,
MONGOC_MSG_NONE,
tmp_bson ("{'$db': 'db',"
Expand Down Expand Up @@ -1406,7 +1406,7 @@ test_find_one_empty (void)
client = test_framework_new_default_client ();
gridfs = get_test_gridfs (client, "list", &error);
ASSERT_OR_PRINT (gridfs, error);
ASSERT (!mongoc_gridfs_find_one (gridfs, tmp_bson ("{'x': 'doesntexist'}"), &error));
ASSERT (!mongoc_gridfs_find_one_with_opts (gridfs, tmp_bson ("{'x': 'doesntexist'}"), NULL, &error));

/* ensure "error" is cleared if we successfully find no file */
ASSERT_CMPUINT32 (error.domain, ==, 0);
Expand Down