Skip to content

Commit

Permalink
Switch to File.OpenRead (#6393)
Browse files Browse the repository at this point in the history
Context
The precomputed cache from dotnet/installer#10037 lives in Program Files after it's installed on a new computer. Program Files can only be accessed with admin privileges, which not all users have and those that have generally wouldn't expect. This permits reading the precomputed cache even without admin rights.

Changes Made
new FileStream(stateFile, FileMode.Open) opens the file as if you had read/write access but only actually grants you read permissions. It still requires administrator privileges, however, if a file requires administrator privileges to write to. This removes that requirement.
  • Loading branch information
Forgind committed May 24, 2021
1 parent 0d1f270 commit 1c6e7ad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Tasks/StateFileBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal static StateFileBase DeserializeCache(string stateFile, TaskLoggingHelp
{
if (!string.IsNullOrEmpty(stateFile) && FileSystems.Default.FileExists(stateFile))
{
using (FileStream s = new FileStream(stateFile, FileMode.Open))
using (FileStream s = File.OpenRead(stateFile))
{
var formatter = new BinaryFormatter();
object deserializedObject = formatter.Deserialize(s);
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/SystemState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ internal static SystemState DeserializeCacheByTranslator(string stateFile, TaskL
{
if (!string.IsNullOrEmpty(stateFile) && FileSystems.Default.FileExists(stateFile))
{
using FileStream s = new FileStream(stateFile, FileMode.Open);
using FileStream s = File.OpenRead(stateFile);
var translator = BinaryTranslator.GetReadTranslator(s, buffer:null); // TODO: shared buffering?

// verify file signature
Expand Down

0 comments on commit 1c6e7ad

Please sign in to comment.