mongoc_gridfs_t * _mongoc_gridfs_new (mongoc_client_t *client, const char *db, const char *prefix, bson_error_t *error) { mongoc_gridfs_t *gridfs; const mongoc_read_prefs_t *read_prefs; const mongoc_read_concern_t *read_concern; const mongoc_write_concern_t *write_concern; char buf[128]; bool r; uint32_t prefix_len; ENTRY; BSON_ASSERT (client); BSON_ASSERT (db); if (!prefix) { prefix = "fs"; } /* make sure prefix is short enough to bucket the chunks and files * collections */ prefix_len = (uint32_t)strlen (prefix); BSON_ASSERT (prefix_len + sizeof (".chunks") < sizeof (buf)); gridfs = (mongoc_gridfs_t *) bson_malloc0 (sizeof *gridfs); gridfs->client = client; read_prefs = mongoc_client_get_read_prefs (client); read_concern = mongoc_client_get_read_concern (client); write_concern = mongoc_client_get_write_concern (client); bson_snprintf (buf, sizeof(buf), "%s.chunks", prefix); gridfs->chunks = _mongoc_collection_new (client, db, buf, read_prefs, read_concern, write_concern); bson_snprintf (buf, sizeof(buf), "%s.files", prefix); gridfs->files = _mongoc_collection_new (client, db, buf, read_prefs, read_concern, write_concern); r = _mongoc_gridfs_ensure_index (gridfs, error); if (!r) { mongoc_gridfs_destroy (gridfs); RETURN (NULL); } RETURN (gridfs); }
mongoc_gridfs_t * _mongoc_gridfs_new (mongoc_client_t *client, const char *db, const char *prefix, bson_error_t *error) { mongoc_gridfs_t *gridfs; char buf[128]; bool r; ENTRY; BSON_ASSERT (client); BSON_ASSERT (db); if (!prefix) { prefix = "fs"; } /* make sure prefix is short enough to bucket the chunks and files * collections */ #ifndef BSON_DISABLE_ASSERT { uint32_t prefix_len; prefix_len = (uint32_t)strlen (prefix); BSON_ASSERT (prefix_len + sizeof (".chunks") < sizeof (buf)); } #endif gridfs = bson_malloc0 (sizeof *gridfs); gridfs->client = client; bson_snprintf (buf, sizeof(buf), "%s.chunks", prefix); gridfs->chunks = _mongoc_collection_new (client, db, buf, NULL, NULL); bson_snprintf (buf, sizeof(buf), "%s.files", prefix); gridfs->files = _mongoc_collection_new (client, db, buf, NULL, NULL); r = _mongoc_gridfs_ensure_index (gridfs, error); if (!r) { return NULL; } RETURN (gridfs); }