Skip to content

Create parent directory when writing output to -fo destination file#531

Merged
sensslen merged 2 commits into
mainfrom
copilot/fix-parent-directory-creation
May 6, 2026
Merged

Create parent directory when writing output to -fo destination file#531
sensslen merged 2 commits into
mainfrom
copilot/fix-parent-directory-creation

Conversation

Copy link
Copy Markdown

Copilot AI commented May 6, 2026

-fo / --output-file fails when the specified file's parent directory doesn't exist — GetOutputStream calls FileMode.Create directly without ensuring the directory exists, unlike -d which already calls CreateDirectory before use.

Changes

  • LicenseValidationOrchestrator.GetOutputStream: Extracts the directory from the resolved full path and calls _fileSystem.Directory.CreateDirectory if it doesn't already exist before opening the file stream.
  • LicenseValidationOrchestratorTest: Adds ValidateAsync_WithDestinationFileInNonExistentDirectory_CreatesDirectoryAndWritesToFile to verify the directory is created and the file is written when intermediate directories are missing.
# Previously failed if ./artifacts/licenses/ didn't exist
nuget-license -i MyProject.csproj -o JsonPretty -fo ./artifacts/licenses/licenses.json

Copilot AI changed the title [WIP] Fix parent directory creation for -fo output files Create parent directory when writing output to -fo destination file May 6, 2026
Copilot AI requested a review from sensslen May 6, 2026 13:10
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-fo does not create parent directory for destination file (fails when folder is missing)

2 participants