private void SaveLooseObject(AnyObjectId id, byte[] compressed)
{
var tmp = new FileInfo(Path.Combine(_local.ObjectsDirectory.ToString(), Path.GetTempFileName()));
try
{
FileStream stream = File.Create(tmp.ToString());
try
{
stream.Write(compressed, 0, compressed.Length);
}
finally
{
stream.Close();
}
tmp.Attributes |= FileAttributes.ReadOnly;
}
catch (IOException)
{
File.Delete(tmp.ToString());
throw;
}
FileInfo o = _local.ToFile(id);
if (tmp.RenameTo(o.ToString()))
return;
Directory.CreateDirectory(tmp.ToString());
if (tmp.RenameTo(o.ToString()))
return;
tmp.Delete();
if (_local.HasObject(id))
return;
throw new ObjectWritingException("Unable to store " + id.Name + ".");
}