diff --git a/FastGithub.Dns/HostsConflictSolver.cs b/FastGithub.Dns/HostsConflictSolver.cs index 58b07d6..362d96a 100644 --- a/FastGithub.Dns/HostsConflictSolver.cs +++ b/FastGithub.Dns/HostsConflictSolver.cs @@ -39,12 +39,14 @@ namespace FastGithub.Dns return; } + var hasConflicting = false; var hostsBuilder = new StringBuilder(); var lines = await File.ReadAllLinesAsync(hostsPath, cancellationToken); foreach (var line in lines) { if (this.IsConflictingLine(line)) { + hasConflicting = true; hostsBuilder.AppendLine($"# {line}"); } else @@ -53,8 +55,11 @@ namespace FastGithub.Dns } } - File.SetAttributes(hostsPath, FileAttributes.Normal); - await File.WriteAllTextAsync(hostsPath, hostsBuilder.ToString(), cancellationToken); + if (hasConflicting == true) + { + File.SetAttributes(hostsPath, FileAttributes.Normal); + await File.WriteAllTextAsync(hostsPath, hostsBuilder.ToString(), cancellationToken); + } } ///