减少不必要的hosts文件写入
This commit is contained in:
parent
a1284a4013
commit
bd56241d54
@ -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,9 +55,12 @@ namespace FastGithub.Dns
|
||||
}
|
||||
}
|
||||
|
||||
if (hasConflicting == true)
|
||||
{
|
||||
File.SetAttributes(hostsPath, FileAttributes.Normal);
|
||||
await File.WriteAllTextAsync(hostsPath, hostsBuilder.ToString(), cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复冲突
|
||||
|
||||
Loading…
Reference in New Issue
Block a user