Skip to content

Commit

Permalink
Try to make InterfaceStubGenerator even more resilient to file skew w…
Browse files Browse the repository at this point in the history
…eirdness
  • Loading branch information
anaisbetts committed Oct 13, 2014
1 parent 0cc422e commit 30198b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
24 changes: 20 additions & 4 deletions InterfaceStubGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Refit.Generator
{
Expand Down Expand Up @@ -34,10 +35,25 @@ static void Main(string[] args)
}

var template = generator.GenerateInterfaceStubs(files.Select(x => x.FullName).ToArray());
using (var of = File.OpenWrite(target.FullName)) {
var bytes = Encoding.UTF8.GetBytes(template);
of.Write(bytes, 0, bytes.Length);
of.Flush();

retry:
int retryCount = 3;
var file = default(FileStream);

// NB: Parallel build weirdness means that we might get >1 person
// trying to party on this file at the same time.
try {
file = File.Open(target.FullName, FileMode.Create, FileAccess.Write, FileShare.None);
} catch (Exception ex) {
if (retryCount < 0) throw;

retryCount--;
Thread.Sleep(500);
goto retry;
}

using (var sw = new StreamWriter(file, Encoding.UTF8)) {
sw.WriteLine(template);
}
}

Expand Down
1 change: 1 addition & 0 deletions Refit-Tests/RefitStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ public virtual Task Post()
}
}


0 comments on commit 30198b3

Please sign in to comment.