/// <exception cref="System.IO.IOException"></exception>
private NGit.Storage.File.ReflogWriter Log(string refName, byte[] rec)
{
FilePath log = LogFor(refName);
bool write = forceWrite || (IsLogAllRefUpdates() && ShouldAutoCreateLog(refName))
|| log.IsFile();
if (!write)
{
return this;
}
WriteConfig wc = GetRepository().GetConfig().Get(WriteConfig.KEY);
FileOutputStream @out;
try
{
@out = new FileOutputStream(log, true);
}
catch (FileNotFoundException err)
{
FilePath dir = log.GetParentFile();
if (dir.Exists())
{
throw;
}
if (!dir.Mkdirs() && !dir.IsDirectory())
{
throw new IOException(MessageFormat.Format(JGitText.Get().cannotCreateDirectory,
dir));
}
@out = new FileOutputStream(log, true);
}
try
{
if (wc.GetFSyncRefFiles())
{
FileChannel fc = @out.GetChannel();
ByteBuffer buf = ByteBuffer.Wrap(rec);
while (0 < buf.Remaining())
{
fc.Write(buf);
}
fc.Force(true);
}
else
{
@out.Write(rec);
}
}
finally
{
@out.Close();
}
return this;
}