Skip to content

Create missing parent directories for FileContent - #1730

Open
Steve Lee (SteveL-MSFT) wants to merge 5 commits into
mainfrom
stevel-msft-fix-file-content-force-path
Open

Steve Lee (SteveL-MSFT) wants to merge 5 commits into
mainfrom
stevel-msft-fix-file-content-force-path

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

Microsoft.Filesystem.File/Content currently fails when a file's parent path does not exist. This change makes the declarative ensure-present behavior create the required directory hierarchy automatically.

  • Create missing parent directories when _exist is true or omitted.
  • Keep _exist: false removal behavior unchanged and avoid adding an imperative force property.
  • Emit a localized DSC-compatible INFO message before directory creation and a specific error if creation fails.
  • Document the behavior and cover explicit and omitted _exist cases.

Tests: Focused FileContent set Pester tests (4 passed).

Fixes: #1728

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 21, 2026 22:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Add coverage for failures caused by an existing file blocking a parent directory.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

Updates Microsoft.Filesystem.File/Content to create missing parent directories during ensure-present operations.

Changes:

  • Creates parent directory hierarchies before writing files.
  • Adds localized informational and error messages.
  • Documents and tests explicit and omitted _exist behavior.
File Description
resources/​filecontent/​tests/​filecontent_set.tests.ps1 Tests directory creation scenarios.
resources/​filecontent/​src/​file.rs Creates missing parent directories.
resources/​filecontent/​locales/​en-us.toml Adds localized messages.
resources/​filecontent/​filecontent.dsc.resource.json Documents directory creation behavior.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread resources/filecontent/src/file.rs
Comment thread resources/filecontent/tests/filecontent_set.tests.ps1 Outdated
Steve Lee (POWERSHELL HE/HIM) (from Dev Box) and others added 2 commits September 21, 2026 16:03
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown

😁 Code Coverage Report

Changed Code Coverage

93% (90%+ coverage)

Metric Value
Changed lines analyzed 16
Lines covered by tests 15
Coverage percentage 93%

🔵 Full Codebase Coverage

82% (good)

Metric Value
Total executable lines 19485
Lines covered by tests 16155
Coverage percentage 82%

Changed code coverage measures only Rust lines added/modified in this PR.
Full codebase coverage measures all instrumented Rust lines across the project.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

An exact parent path that is a file bypasses the new directory-creation error handling.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Validate parent path is a directory before writing

resources/​filecontent/​src/​file.rs:43

Checking only exists() treats a regular file at the exact parent path as a valid parent. For a target such as <root>/blocked/file.txt where <root>/blocked is a file, this skips create_dir_all and falls through to the generic write error instead of the new parent-directory diagnostic. Check whether the parent is a directory so this conflict uses the intended creation failure path; the negative test should also exercise this exact-parent case.

Steve Lee (POWERSHELL HE/HIM) (from Dev Box) and others added 2 commits September 21, 2026 18:53
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

Microsoft.Filesystem.File/Content - Froce tor create path if don't exist

2 participants