Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Commit

Permalink
OpenWrite overwrites and does not share (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaggart authored Dec 26, 2017
1 parent b0ab2dc commit 1f46401
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SourceLink.Create.CommandLine/CreateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override bool Execute()
rootDirectory += '*';
rootDirectory = rootDirectory.Replace(@"\", @"\\"); // json escape

using (var json = new IO.StreamWriter(IO.File.OpenWrite(File)))
using (var json = FileUtil.OpenWrite(File))
{
json.Write("{\"documents\":{\"");
json.Write(rootDirectory);
Expand Down
11 changes: 11 additions & 0 deletions SourceLink.Create.Shared/FileUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.IO;

namespace SourceLink.Create
{
public static class FileUtil
{
public static StreamWriter OpenWrite(string file) {
return new StreamWriter(File.Open(file, FileMode.Create, FileAccess.Write, FileShare.None));
}
}
}
2 changes: 1 addition & 1 deletion SourceLink.Create.Shared/GitCreateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override bool Execute()
}

var compileFile = IO.Path.ChangeExtension(File, ".compile");
using (var sw = new IO.StreamWriter(IO.File.OpenWrite(compileFile)))
using (var sw = FileUtil.OpenWrite(compileFile))
{
if (Sources != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Import_RootNamespace>SourceLink.Create</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)FileUtil.cs" />
<Compile Include="$(MSBuildThisFileDirectory)GitCreateTask.cs" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$version = '2.6.1' # the version under development, update after a release
$version = '2.7.0' # the version under development, update after a release
$versionSuffix = '-a125' # manually incremented for local builds

function isVersionTag($tag){
Expand Down
4 changes: 2 additions & 2 deletions dotnet-sourcelink-git/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public static void Create(CommandLineApplication command)
}
};

using (var sw = new StreamWriter(File.OpenWrite(file)))
using (var sw = FileUtil.OpenWrite(file))
{
var js = new JsonSerializer();
js.Serialize(sw, json);
Expand All @@ -262,7 +262,7 @@ public static void Create(CommandLineApplication command)
if (embedFiles.Count > 0)
{
Console.WriteLine("embedding " + embedFiles.Count + " source files");
using (var sw = new StreamWriter(File.OpenWrite(embedFile)))
using (var sw = FileUtil.OpenWrite(embedFile))
{
foreach (var sf in embedFiles)
{
Expand Down
11 changes: 11 additions & 0 deletions dotnet-sourcelink-shared/FileUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.IO;

namespace SourceLink
{
public static class FileUtil
{
public static StreamWriter OpenWrite(string file) {
return new StreamWriter(File.Open(file, FileMode.Create, FileAccess.Write, FileShare.None));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Import_RootNamespace>SourceLink</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)FileUtil.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SourceLinkJson.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Version.cs" />
Expand Down

0 comments on commit 1f46401

Please sign in to comment.