Skip to content

Commit 59878b7

Browse files
authored
CSHARP-5304: Mark MD5 support in GridFS as Obsolete in 2.x (#1484)
1 parent c4f48da commit 59878b7

14 files changed

+59
-2
lines changed

src/MongoDB.Driver.GridFS/GridFSBucket.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,9 @@ private BulkMixedWriteOperation CreateDeleteChunksOperation(TFileId id)
577577

578578
private GridFSDownloadStream<TFileId> CreateDownloadStream(IReadBindingHandle binding, GridFSFileInfo<TFileId> fileInfo, GridFSDownloadOptions options, CancellationToken cancellationToken = default(CancellationToken))
579579
{
580+
#pragma warning disable CS0618 // Type or member is obsolete
580581
var checkMD5 = options.CheckMD5 ?? false;
582+
#pragma warning restore CS0618 // Type or member is obsolete
581583
var seekable = options.Seekable ?? false;
582584
if (checkMD5 && seekable)
583585
{
@@ -777,7 +779,9 @@ private GridFSUploadStream<TFileId> CreateUploadStream(IReadWriteBindingHandle b
777779

778780
private void DownloadToStreamHelper(IReadBindingHandle binding, GridFSFileInfo<TFileId> fileInfo, Stream destination, GridFSDownloadOptions options, CancellationToken cancellationToken = default(CancellationToken))
779781
{
782+
#pragma warning disable CS0618 // Type or member is obsolete
780783
var checkMD5 = options.CheckMD5 ?? false;
784+
#pragma warning restore CS0618 // Type or member is obsolete
781785

782786
var retryReads = _database.Client.Settings.RetryReads;
783787
using (var source = new GridFSForwardOnlyDownloadStream<TFileId>(this, binding.Fork(), fileInfo, checkMD5) { RetryReads = retryReads })
@@ -798,7 +802,9 @@ private GridFSUploadStream<TFileId> CreateUploadStream(IReadWriteBindingHandle b
798802

799803
private async Task DownloadToStreamHelperAsync(IReadBindingHandle binding, GridFSFileInfo<TFileId> fileInfo, Stream destination, GridFSDownloadOptions options, CancellationToken cancellationToken = default(CancellationToken))
800804
{
805+
#pragma warning disable CS0618 // Type or member is obsolete
801806
var checkMD5 = options.CheckMD5 ?? false;
807+
#pragma warning restore CS0618 // Type or member is obsolete
802808

803809
var retryReads = _database.Client.Settings.RetryReads;
804810
using (var source = new GridFSForwardOnlyDownloadStream<TFileId>(this, binding.Fork(), fileInfo, checkMD5) { RetryReads = retryReads })

src/MongoDB.Driver.GridFS/GridFSBucketOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
1617
using MongoDB.Bson.Serialization;
1718
using MongoDB.Driver.Core.Misc;
1819

@@ -49,7 +50,9 @@ public GridFSBucketOptions(GridFSBucketOptions other)
4950
Ensure.IsNotNull(other, nameof(other));
5051
_bucketName = other.BucketName;
5152
_chunkSizeBytes = other.ChunkSizeBytes;
53+
#pragma warning disable CS0618 // Type or member is obsolete
5254
_disableMD5 = other.DisableMD5;
55+
#pragma warning restore CS0618 // Type or member is obsolete
5356
_readConcern = other.ReadConcern;
5457
_readPreference = other.ReadPreference;
5558
_writeConcern = other.WriteConcern;
@@ -64,7 +67,9 @@ public GridFSBucketOptions(ImmutableGridFSBucketOptions other)
6467
Ensure.IsNotNull(other, nameof(other));
6568
_bucketName = other.BucketName;
6669
_chunkSizeBytes = other.ChunkSizeBytes;
70+
#pragma warning disable CS0618 // Type or member is obsolete
6771
_disableMD5 = other.DisableMD5;
72+
#pragma warning restore CS0618 // Type or member is obsolete
6873
_readConcern = other.ReadConcern;
6974
_readPreference = other.ReadPreference;
7075
_writeConcern = other.WriteConcern;
@@ -109,6 +114,7 @@ public int ChunkSizeBytes
109114
/// <value>
110115
/// Whether MD5 checksum computation is disabled when uploading a GridFS file.
111116
/// </value>
117+
[Obsolete("MD5 support will be removed in a later release.")]
112118
public bool DisableMD5
113119
{
114120
get { return _disableMD5; }
@@ -201,7 +207,9 @@ public ImmutableGridFSBucketOptions(GridFSBucketOptions other)
201207
Ensure.IsNotNull(other, nameof(other));
202208
_bucketName = other.BucketName;
203209
_chunkSizeBytes = other.ChunkSizeBytes;
210+
#pragma warning disable CS0618 // Type or member is obsolete
204211
_disableMD5 = other.DisableMD5;
212+
#pragma warning restore CS0618 // Type or member is obsolete
205213
_readConcern = other.ReadConcern;
206214
_readPreference = other.ReadPreference;
207215
_writeConcern = other.WriteConcern;
@@ -236,6 +244,7 @@ public int ChunkSizeBytes
236244
/// <value>
237245
/// Whether MD5 checksum computation is disabled when uploading a GridFS file.
238246
/// </value>
247+
[Obsolete("MD5 support will be removed in a later release.")]
239248
public bool DisableMD5
240249
{
241250
get { return _disableMD5; }

src/MongoDB.Driver.GridFS/GridFSDownloadOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
17+
1618
namespace MongoDB.Driver.GridFS
1719
{
1820
/// <summary>
@@ -31,6 +33,7 @@ public class GridFSDownloadOptions
3133
/// <value>
3234
/// <c>true</c> if the MD5 value should be checked; otherwise, <c>false</c>.
3335
/// </value>
36+
[Obsolete("MD5 support will be removed in a later release.")]
3437
public bool? CheckMD5
3538
{
3639
get { return _checkMD5; }

src/MongoDB.Driver.GridFS/GridFSFileInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public long Length
129129
/// <value>
130130
/// The MD5 checksum.
131131
/// </value>
132+
[Obsolete("MD5 support will be removed in a later release.")]
132133
public string MD5
133134
{
134135
get { return GetValue<string>("MD5", null); }

src/MongoDB.Driver.GridFS/GridFSForwardOnlyDownloadStream.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ protected override void CloseImplementation(CancellationToken cancellationToken)
157157
if (_checkMD5 && _position == FileInfo.Length)
158158
{
159159
var md5 = BsonUtils.ToHexString(_md5.GetHashAndReset());
160+
#pragma warning disable CS0618 // Type or member is obsolete
160161
if (!md5.Equals(FileInfo.MD5, StringComparison.OrdinalIgnoreCase))
161162
{
162-
#pragma warning disable 618
163163
throw new GridFSMD5Exception(_idAsBsonValue);
164-
#pragma warning restore
165164
}
165+
#pragma warning restore CS0618 // Type or member is obsolete
166166
}
167167
}
168168

src/MongoDB.Driver.GridFS/GridFSMD5Exception.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace MongoDB.Driver.GridFS
2424
/// Represents a GridFSMD5 exception.
2525
/// </summary>
2626
[Serializable]
27+
[Obsolete("MD5 support will be removed in a later release.")]
2728
public class GridFSMD5Exception : GridFSException
2829
{
2930
#region static

src/MongoDB.Driver.GridFS/GridFSUploadOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public string ContentType
9494
/// <value>
9595
/// Whether or not MD5 checksum computation is disabled when uploading a GridFS file.
9696
/// </value>
97+
[Obsolete("MD5 support will be removed in a later release.")]
9798
public bool DisableMD5
9899
{
99100
get { return _disableMD5; }

tests/MongoDB.Driver.GridFS.Tests/GridFSBucketOptionsTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ public void constructor_with_no_arguments_should_initialize_instance_with_defaul
144144
public void DisableMD5_get_and_set_should_return_expected_result(
145145
[Values(false, true)] bool disabled)
146146
{
147+
#pragma warning disable CS0618 // Type or member is obsolete
147148
var subject = new GridFSBucketOptions { DisableMD5 = disabled };
148149

149150
var result = subject.DisableMD5;
151+
#pragma warning restore CS0618 // Type or member is obsolete
150152

151153
result.Should().Be(disabled);
152154
}
@@ -241,7 +243,9 @@ public void constructor_with_arguments_should_initialize_instance()
241243
{
242244
BucketName = "bucket",
243245
ChunkSizeBytes = 123,
246+
#pragma warning disable CS0618 // Type or member is obsolete
244247
DisableMD5 = true,
248+
#pragma warning restore CS0618 // Type or member is obsolete
245249
ReadConcern = ReadConcern.Majority,
246250
ReadPreference = ReadPreference.Secondary,
247251
WriteConcern = WriteConcern.WMajority
@@ -251,7 +255,9 @@ public void constructor_with_arguments_should_initialize_instance()
251255

252256
result.BucketName.Should().Be("bucket");
253257
result.ChunkSizeBytes.Should().Be(123);
258+
#pragma warning disable CS0618 // Type or member is obsolete
254259
result.DisableMD5.Should().Be(true);
260+
#pragma warning restore CS0618 // Type or member is obsolete
255261
result.ReadConcern.Should().Be(ReadConcern.Majority);
256262
result.ReadPreference.Should().Be(ReadPreference.Secondary);
257263
result.WriteConcern.Should().Be(WriteConcern.WMajority);
@@ -264,7 +270,9 @@ public void constructor_with_no_arguments_should_initialize_instance_with_defaul
264270

265271
result.BucketName.Should().Be("fs");
266272
result.ChunkSizeBytes.Should().Be(255 * 1024);
273+
#pragma warning disable CS0618 // Type or member is obsolete
267274
result.DisableMD5.Should().Be(false);
275+
#pragma warning restore CS0618 // Type or member is obsolete
268276
result.ReadConcern.Should().BeNull();
269277
result.ReadPreference.Should().BeNull();
270278
result.WriteConcern.Should().BeNull();
@@ -286,7 +294,9 @@ public void Defaults_get_should_return_expected_result()
286294

287295
result.BucketName.Should().Be("fs");
288296
result.ChunkSizeBytes.Should().Be(255 * 1024);
297+
#pragma warning disable CS0618 // Type or member is obsolete
289298
result.DisableMD5.Should().Be(false);
299+
#pragma warning restore CS0618 // Type or member is obsolete
290300
result.ReadConcern.Should().BeNull();
291301
result.ReadPreference.Should().BeNull();
292302
result.WriteConcern.Should().BeNull();
@@ -297,9 +307,11 @@ public void Defaults_get_should_return_expected_result()
297307
public void DisableMD5_get_and_set_should_return_expected_result(
298308
[Values(false, true)] bool disabled)
299309
{
310+
#pragma warning disable CS0618 // Type or member is obsolete
300311
var subject = new ImmutableGridFSBucketOptions(new GridFSBucketOptions { DisableMD5 = disabled });
301312

302313
var result = subject.DisableMD5;
314+
#pragma warning restore CS0618 // Type or member is obsolete
303315

304316
result.Should().Be(disabled);
305317
}

tests/MongoDB.Driver.GridFS.Tests/GridFSBucketTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public void constructor_should_initialize_instance()
4545
result.Database.Should().BeSameAs(database);
4646
result.Options.BucketName.Should().Be(options.BucketName);
4747
result.Options.ChunkSizeBytes.Should().Be(options.ChunkSizeBytes);
48+
#pragma warning disable CS0618 // Type or member is obsolete
4849
result.Options.DisableMD5.Should().Be(options.DisableMD5);
50+
#pragma warning restore CS0618 // Type or member is obsolete
4951
result.Options.ReadPreference.Should().Be(options.ReadPreference);
5052
result.Options.WriteConcern.Should().Be(options.WriteConcern);
5153
}
@@ -473,7 +475,9 @@ public void Options_get_should_return_the_expected_result()
473475

474476
result.BucketName.Should().Be(options.BucketName);
475477
result.ChunkSizeBytes.Should().Be(options.ChunkSizeBytes);
478+
#pragma warning disable CS0618 // Type or member is obsolete
476479
result.DisableMD5.Should().Be(options.DisableMD5);
480+
#pragma warning restore CS0618 // Type or member is obsolete
477481
result.ReadConcern.Should().Be(options.ReadConcern);
478482
result.ReadPreference.Should().Be(options.ReadPreference);
479483
result.WriteConcern.Should().Be(options.WriteConcern);

tests/MongoDB.Driver.GridFS.Tests/GridFSDownloadOptionsTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public class GridFSDownloadOptionsTests
2828
[Fact]
2929
public void CheckMD5_get_should_return_expected_result()
3030
{
31+
#pragma warning disable CS0618 // Type or member is obsolete
3132
var subject = new GridFSDownloadOptions { CheckMD5 = true };
3233

3334
var result = subject.CheckMD5;
35+
#pragma warning restore CS0618 // Type or member is obsolete
3436

3537
result.Should().Be(true);
3638
}
@@ -40,17 +42,21 @@ public void CheckMD5_set_should_have_expected_result()
4042
{
4143
var subject = new GridFSDownloadOptions();
4244

45+
#pragma warning disable CS0618 // Type or member is obsolete
4346
subject.CheckMD5 = true;
4447

4548
subject.CheckMD5.Should().Be(true);
49+
#pragma warning restore CS0618 // Type or member is obsolete
4650
}
4751

4852
[Fact]
4953
public void default_constructor_should_return_expected_result()
5054
{
5155
var result = new GridFSDownloadOptions();
5256

57+
#pragma warning disable CS0618 // Type or member is obsolete
5358
result.CheckMD5.Should().NotHaveValue();
59+
#pragma warning restore CS0618 // Type or member is obsolete
5460
result.Seekable.Should().NotHaveValue();
5561
}
5662

tests/MongoDB.Driver.GridFS.Tests/GridFSMD5ExceptionTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,39 @@ public class GridFSMD5ExceptionTests
2626
[Fact]
2727
public void constructor_should_initialize_instance()
2828
{
29+
#pragma warning disable CS0618 // Type or member is obsolete
2930
var result = new GridFSMD5Exception(123);
31+
#pragma warning restore CS0618 // Type or member is obsolete
3032

3133
result.Message.Should().Contain("id 123");
3234
}
3335

3436
[Fact]
3537
public void constructor_should_throw_when_id_is_null()
3638
{
39+
#pragma warning disable CS0618 // Type or member is obsolete
3740
Action action = () => new GridFSMD5Exception(null);
41+
#pragma warning restore CS0618 // Type or member is obsolete
3842

3943
action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("id");
4044
}
4145

4246
[Fact]
4347
public void Serialization_should_work()
4448
{
49+
#pragma warning disable CS0618 // Type or member is obsolete
4550
var subject = new GridFSMD5Exception(123);
51+
#pragma warning restore CS0618 // Type or member is obsolete
4652

4753
var formatter = new BinaryFormatter();
4854
using (var stream = new MemoryStream())
4955
{
5056
#pragma warning disable SYSLIB0011 // BinaryFormatter serialization is obsolete
5157
formatter.Serialize(stream, subject);
5258
stream.Position = 0;
59+
#pragma warning disable CS0618 // Type or member is obsolete
5360
var rehydrated = (GridFSMD5Exception)formatter.Deserialize(stream);
61+
#pragma warning restore CS0618 // Type or member is obsolete
5462
#pragma warning restore SYSLIB0011 // BinaryFormatter serialization is obsolete
5563

5664
rehydrated.Message.Should().Be(subject.Message);

tests/MongoDB.Driver.GridFS.Tests/Specifications/gridfs/GridFSDownloadAsBytesByNameTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ private void ParseOptions(BsonDocument options)
7979
switch (option.Name)
8080
{
8181
case "checkMD5":
82+
#pragma warning disable CS0618 // Type or member is obsolete
8283
_options.CheckMD5 = option.Value.ToBoolean();
84+
#pragma warning restore CS0618 // Type or member is obsolete
8385
break;
8486

8587
case "revision":

tests/MongoDB.Driver.GridFS.Tests/Specifications/gridfs/GridFSDownloadAsBytesTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ private void ParseOptions(BsonDocument options)
7979
switch (option.Name)
8080
{
8181
case "checkMD5":
82+
#pragma warning disable CS0618 // Type or member is obsolete
8283
_options.CheckMD5 = option.Value.ToBoolean();
84+
#pragma warning restore CS0618 // Type or member is obsolete
8385
break;
8486

8587
default:

tests/MongoDB.Driver.GridFS.Tests/Specifications/gridfs/GridFSUploadFromBytesTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ private void ParseOptions(BsonDocument options)
101101
break;
102102

103103
case "disableMD5":
104+
#pragma warning disable CS0618 // Type or member is obsolete
104105
_options.DisableMD5 = option.Value.AsBoolean;
106+
#pragma warning restore CS0618 // Type or member is obsolete
105107
break;
106108

107109
case "metadata":

0 commit comments

Comments
 (0)