Skip to content

Commit c278bbe

Browse files
committed
refactor: Minor improvements to IsLinuxGoogleBiosAsync
- 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
1 parent 90f0a47 commit c278bbe

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Src/Support/Google.Apis.Auth/OAuth2/ComputeCredential.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,8 @@ async Task<bool> IsLinuxGoogleBiosAsync()
477477
return false;
478478
}
479479

480-
string productName;
481-
using (var streamReader = new StreamReader(new FileStream("/sys/class/dmi/id/product_name", FileMode.Open, FileAccess.Read)))
482-
{
483-
productName = await streamReader.ReadLineAsync().ConfigureAwait(false);
484-
}
480+
using var reader = File.OpenText(fileName);
481+
string productName = await reader.ReadLineAsync().ConfigureAwait(false);
485482
productName = productName?.Trim();
486483
return productName == "Google" || productName == "Google Compute Engine";
487484
}

0 commit comments

Comments
 (0)