Skip to content

Commit

Permalink
If FileStream.Lock is not supported, show an error message about mode…
Browse files Browse the repository at this point in the history
…=Exclusive
  • Loading branch information
michaelstum committed Feb 16, 2018
1 parent 79e2dbb commit 731e311
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion LiteDB/Utils/Extensions/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public static bool TryUnlock(this FileStream stream, long position, long length)
{
return false;
}
catch (PlatformNotSupportedException pex)
{
throw CreateLockNotSupportedException(pex);
}
}

/// <summary>
Expand All @@ -59,9 +63,21 @@ public static void TryLock(this FileStream stream, long position, long length, T

FileHelper.TryExec(() =>
{
stream.Lock(position, length);
try
{
stream.Lock(position, length);
}
catch (PlatformNotSupportedException pex)
{
throw CreateLockNotSupportedException(pex);
}
}, timeout);
}

private static Exception CreateLockNotSupportedException(PlatformNotSupportedException innerEx)
{
throw new InvalidOperationException("Your platform does not support FileStream.Lock. Please set mode=Exclusive in your connnection string to avoid this error.", innerEx);
}
#endif
}
}

0 comments on commit 731e311

Please sign in to comment.