Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions Bonobo.Git.Server/Git/GitService/GitServiceExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using System.Web.Mvc;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;

namespace Bonobo.Git.Server.Git.GitService
{
Expand Down Expand Up @@ -37,6 +37,12 @@ public GitServiceExecutor(GitServiceExecutorParams parameters, IGitRepositoryLoc
this.repoLocator = repoLocator;
}

private class StreamHelper
{
public Stream FromStream { get; set; }
public Stream ToStream { get; set; }
}

public void ExecuteServiceByName(
string correlationId,
string repositoryName,
Expand Down Expand Up @@ -93,18 +99,41 @@ public void ExecuteServiceByName(

using (var process = Process.Start(info))
{
inStream.CopyTo(process.StandardInput.BaseStream);
if (options.endStreamWithClose) {
process.StandardInput.Close();
} else {
process.StandardInput.Write('\0');
}

process.StandardOutput.BaseStream.CopyTo(outStream);
process.WaitForExit();
var readStreamHelper = new StreamHelper {
FromStream = process.StandardOutput.BaseStream,
ToStream = outStream
};

//Seperate thread for reading the output to prevent a buffer overflow at the 4k console buffer limit
var thrdRead = new Thread((obj) => {
try
{
var strmHelper = (StreamHelper) obj;
strmHelper.FromStream.CopyTo(strmHelper.ToStream);
}
//Extra to prevent error if client disconnected
catch (System.Web.HttpException)
{
}
});

thrdRead.Start(readStreamHelper);

inStream.CopyTo(process.StandardInput.BaseStream);
if (options.endStreamWithClose) {
process.StandardInput.Close();
} else {
process.StandardInput.Write('\0');
}

process.WaitForExit();

thrdRead.Abort();

}
}


private void SetHomePath(ProcessStartInfo info)
{
if (info.EnvironmentVariables.ContainsKey("HOME"))
Expand Down