Skip to content

Commit

Permalink
refactor: Minor improvements to IsLinuxGoogleBiosAsync
Browse files Browse the repository at this point in the history
- Avoid having the same string literal twice
- Use the simpler File.OpenText instead of constructing a StreamReader explicitly
- Use a `using` declaration to simplify the rest of the code

Fixes b/335638570
  • Loading branch information
jskeet committed Apr 19, 2024
1 parent 90f0a47 commit c278bbe
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Src/Support/Google.Apis.Auth/OAuth2/ComputeCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,8 @@ async Task<bool> IsLinuxGoogleBiosAsync()
return false;
}

string productName;
using (var streamReader = new StreamReader(new FileStream("/sys/class/dmi/id/product_name", FileMode.Open, FileAccess.Read)))
{
productName = await streamReader.ReadLineAsync().ConfigureAwait(false);
}
using var reader = File.OpenText(fileName);
string productName = await reader.ReadLineAsync().ConfigureAwait(false);
productName = productName?.Trim();
return productName == "Google" || productName == "Google Compute Engine";
}
Expand Down

0 comments on commit c278bbe

Please sign in to comment.