Use SpecialFolderOption.DoNotVerify in GetFolderPath to avoid empty path on Linux#54510
Use SpecialFolderOption.DoNotVerify in GetFolderPath to avoid empty path on Linux#54510Copilot wants to merge 5 commits into
Conversation
…th on Linux Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
|
@copilot is there a good way to add a test that checks this scenario (e.g. overriding environment variables based on the runtime implementation, launching the dotnetup e2e process) - since there is no file system mock? I'd like to be able to prevent regression here. |
Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Yes — since I added
It's gated to Linux/FreeBSD (where |
|
@copilot I think this is the wrong location - the linked issue is about the use of this method in dotnetup, not the dotnet CLI primarily. |
|
@copilot you need to use release/dnup as a base branch and make a PR into there, not main. |
| string directory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) | ||
| ? Path.GetTempPath() | ||
| : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | ||
| : Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create); |
There was a problem hiding this comment.
Use SpecialFolderOption.DoNotVerify instead of SpecialFolderOption.Create, so that the path is computed regardless of whether it exists yet. dotnetup creates it later via EnsureDataDirectoryExists.
There was a problem hiding this comment.
Done — switched to SpecialFolderOption.DoNotVerify in both VirtualProjectBuilder.GetTempSubdirectory() and DotnetupPaths.GetBaseDirectory(). The directory creation is left to the existing EnsureDataDirectoryExists call. Commit: Use SpecialFolderOption.DoNotVerify instead of Create in GetFolderPath calls.
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Fixed in the latest commit. |
…h calls Co-authored-by: nagilson <36081148+nagilson@users.noreply.github.com>
Noted — I'm not able to retarget the PR's base branch directly. Please retarget this PR to |
Environment.GetFolderPath(SpecialFolder.LocalApplicationData)returns an empty string on Linux when~/.local/sharedoesn't exist (documented BCL behavior). Two locations in the SDK treat this as a fatal error, breaking functionality on minimal Linux environments (e.g., bare GitHub Ubuntu runners).Changes
DotnetupPaths.GetBaseDirectory()(primary fix): Switch to the two-argument overload withSpecialFolderOption.DoNotVerify, so the path is computed regardless of whether the directory exists yet — preventing dotnetup from throwingInvalidOperationExceptionon bare Linux environments. Directory creation is handled later by the existingEnsureDataDirectoryExistscall.VirtualProjectBuilder.GetTempSubdirectory(): Same fix applied — ensuresdotnet run <file>does not fail on Linux when~/.local/shareis absent.VirtualProjectBuilderTests(new): Added a regression test (GetTempSubdirectory_ReturnsNonEmptyPath_WhenXdgDataHomeDoesNotExist) that setsXDG_DATA_HOMEto a non-existent directory and verifiesGetTempSubdirectory()returns a valid, non-empty path rooted under it. The test is gated to Linux/FreeBSD via[PlatformSpecificFact(TestPlatforms.Linux | TestPlatforms.FreeBSD)].