public static void WriteAllTextAtomic(string filePath, string value, bool deleteOnError)
{
var tempPath = CreateTmpName(filePath);
try
{
CreateNonExistentDirectory(Path.GetDirectoryName(filePath));
File.WriteAllText(tempPath, value);
DeleteFile(filePath);
File.Move(tempPath, filePath);
}
catch (Exception)
{
if (deleteOnError)
{
DeleteFileSilently(filePath);
}
DeleteFileSilently(tempPath);
throw;
}
}