Skip to content

Commit 8ef0d14

Browse files
author
Piotr Rutkowski
committed
CL-143 Fix file lock release
* Files access fixed: class FileSide is now IDisposable * disposing FileSide instance frees the local file lock
1 parent 63477fc commit 8ef0d14

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
v1.1.6
5+
------
6+
7+
- Files access fixed: class `FileSide` is now `IDisposable` - disposing `FileSide` instance frees the local file lock
8+
49
v1.1.5
510
------
611

src/Draftable.CompareAPI.Client/Comparisons.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,25 @@ public async Task DeleteAsync([NotNull] string identifier, CancellationToken can
536536
/// other overloads to create <see cref="Side" /> objects.
537537
/// </remarks>
538538
[PublicAPI]
539-
public abstract class Side
539+
public abstract class Side : IDisposable
540540
{
541541
internal Side() { }
542542

543543
[NotNull] protected abstract IEnumerable<KeyValuePair<string, string>> FormData { get; }
544544

545545
[NotNull] protected abstract IEnumerable<KeyValuePair<string, Stream>> FileContent { get; }
546546

547+
protected virtual void Dispose(bool disposing)
548+
{
549+
// does nothing.
550+
}
551+
552+
public void Dispose()
553+
{
554+
Dispose(true);
555+
GC.SuppressFinalize(this);
556+
}
557+
547558
/// <exception cref="ArgumentOutOfRangeException"><paramref name="sideName" /> must be one of "left" or "right".</exception>
548559
[Pure]
549560
[NotNull]
@@ -725,6 +736,12 @@ internal FileSide([NotNull] Stream file, [NotNull] string fileType, [CanBeNull]
725736

726737
protected override IEnumerable<KeyValuePair<string, Stream>> FileContent =>
727738
new[] {new KeyValuePair<string, Stream>("file", _file)};
739+
740+
protected override void Dispose(bool disposing)
741+
{
742+
base.Dispose(disposing);
743+
_file.Dispose();
744+
}
728745
}
729746

730747

src/Sample.Core/ComparisonsSample.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ private static Comparison CreateComparisonFromData(Comparisons client)
140140
{
141141
var identifier = Comparisons.GenerateIdentifier();
142142

143-
return client.Create(Comparisons.Side.FromFile(SampleFileLeft),
144-
Comparisons.Side.FromFile(SampleFileRight),
143+
using(var leftSide = Comparisons.Side.FromFile(SampleFileLeft))
144+
using(var rightSide = Comparisons.Side.FromFile(SampleFileRight))
145+
return client.Create(leftSide,
146+
rightSide,
145147
identifier,
146148
expires: TimeSpan.FromMinutes(30));
147149
}

0 commit comments

Comments
 (0)