Skip to content

Commit 9ae40c9

Browse files
committed
Fix issue with file permissions and include unit test for it
1 parent b4de709 commit 9ae40c9

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/Unosquare.Labs.EmbedIO/Modules/StaticFilesModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private bool HandleGet(HttpListenerContext context, WebServer server, bool sendB
240240

241241
if (sendBuffer)
242242
{
243-
buffer = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.Read);
243+
buffer = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
244244

245245
if (usingPartial == false)
246246
{

test/Unosquare.Labs.EmbedIO.Tests/StaticFilesModuleTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,30 @@ public async Task HeadIndex()
317317
}
318318
}
319319

320+
[Test]
321+
public async Task FileWritable()
322+
{
323+
var endpoint = Resources.GetServerAddress();
324+
var root = Path.GetTempPath();
325+
var file = Path.Combine(root, "index.html");
326+
File.WriteAllText(file, Resources.Index);
327+
328+
using (var server = new WebServer(endpoint, Logger))
329+
{
330+
server.RegisterModule(new StaticFilesModule(root));
331+
server.RunAsync();
332+
333+
var webClient = new HttpClient();
334+
var remoteFile = await webClient.GetStringAsync(endpoint);
335+
File.WriteAllText(file, Resources.SubIndex);
336+
var remoteUpdatedFile = await webClient.GetStringAsync(endpoint);
337+
File.WriteAllText(file, nameof(WebServer));
338+
339+
Assert.AreEqual(Resources.Index, remoteFile);
340+
Assert.AreEqual(Resources.SubIndex, remoteUpdatedFile);
341+
}
342+
}
343+
320344
[TearDown]
321345
public void Kill()
322346
{

test/Unosquare.Labs.EmbedIO.Tests/TestObjects/Resources.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace Unosquare.Labs.EmbedIO.Tests.TestObjects
55
public static class Resources
66
{
77
private const string ServerAddress = "http://localhost:{0}/";
8-
public static int Counter = 9699;
8+
public static int Counter = 9699;
9+
910
public static string GetServerAddress(){
1011
Interlocked.Increment(ref Counter);
1112
return string.Format(ServerAddress, Counter);

0 commit comments

Comments
 (0)