Skip to content

Commit 927be77

Browse files
committed
Fix project settings file getting corrupted
1 parent ae200af commit 927be77

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

source/VersionHandlerImpl/src/ProjectSettings.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,9 @@ private static void Save() {
818818
return;
819819
}
820820
try {
821+
string tmpFile = Path.GetTempFileName();
821822
using (var writer =
822-
XmlWriter.Create(PROJECT_SETTINGS_FILE,
823+
XmlWriter.Create(tmpFile,
823824
new XmlWriterSettings {
824825
Encoding = new UTF8Encoding(false),
825826
Indent = true,
@@ -839,6 +840,8 @@ private static void Save() {
839840
}
840841
writer.WriteEndElement();
841842
}
843+
844+
File.Copy(tmpFile, PROJECT_SETTINGS_FILE, true);
842845
} catch (Exception exception) {
843846
if (exception is IOException || exception is UnauthorizedAccessException) {
844847
logger.Log(String.Format("Unable to write to '{0}' ({1}, " +
@@ -848,6 +851,10 @@ private static void Save() {
848851
}
849852
throw exception;
850853
}
854+
finally
855+
{
856+
File.Delete(tmpFile);
857+
}
851858
}
852859
}
853860
}

0 commit comments

Comments
 (0)