Skip to content

Commit 58e2310

Browse files
committed
Removing app.js before writing to it to avoid partial writes
Fixes #128
1 parent c5b7e62 commit 58e2310

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/ServicePulse.Host/Commands/AbstractCommand.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ public static void UpdateConfig(string directoryPath, string serviceControlUrl)
1212
{
1313
var appJsPath = Path.Combine(directoryPath, "config.js");
1414
var appJsCode = File.ReadAllText(appJsPath);
15+
16+
if (File.Exists(appJsPath))
17+
{
18+
File.Delete(appJsPath);
19+
}
20+
1521
File.WriteAllText(appJsPath,
1622
Regex.Replace(appJsCode, @"(service_control_url: ')([\w:/]*)(')", "$1" + serviceControlUrl + "$3"));
1723
}

src/ServicePulse.Host/Commands/UpdateVersionCommand.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@ static void UpdateVersion(string directoryPath)
3535
{
3636
var appJsPath = Path.Combine(directoryPath, "js/app.js");
3737
var appJsCode = File.ReadAllText(appJsPath);
38-
File.WriteAllText(appJsPath,
39-
Regex.Replace(appJsCode, @"(constant\('version', ')([\w:/.-]*)(')", "${1}" + GetFileVersion() + "$3"));
38+
39+
if (File.Exists(appJsPath))
40+
{
41+
File.Delete(appJsPath);
42+
}
43+
44+
var updatedContent = Regex.Replace(appJsCode, @"(constant\('version', ')([\w:/.-]*)(')", "${1}" + GetFileVersion() + "$3");
45+
46+
File.WriteAllText(appJsPath, updatedContent);
4047
}
4148

4249
static string GetFileVersion()

0 commit comments

Comments
 (0)