Fix Windows file locking error when rendering with --output-dir #13626
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When rendering with
--output-diron Windows without a project file, Quarto would fail with:Root Cause
When
--output-diris used without a project file, Quarto creates a "synthetic" project context with a temporary.quartodirectory to manage the render. The issue was a timing problem in cleanup ordering:.quartodirectory.quartois still opencontext.cleanup()(which closes the KV file) is called later by the callerFix
Call
context.cleanup()before attempting to remove the.quartodirectory. This ensures file handles are properly closed first.The fix is minimal (5 lines) and safe because
cleanup()is idempotent (wrapped withonce()), so calling it early and again later has no side effects.Alternative Approach Considered
Initially implemented a path registration mechanism where code could register paths for cleanup at the point of decision. This added
cleanupPathsarray andregisterForCleanup()method toProjectContext, with cleanup logic duplicated across 4 locations.This was deemed too complex for a single use case (82 lines across 6 files). The simpler ordering fix achieves the same result.
Documentation
Added comments explaining the "synthetic project" pattern:
--output-diris used without_quarto.yml, Quarto creates a temporary project contextforceCleanflag signals this is temporary and needs cleanupsrc/command/render/render-shared.ts:52-58src/command/render/project.ts:889-907Added tests in
tests/smoke/render/render-output-dir.test.tscovering both default cleanup behavior and--no-cleanflag preservation.Fixes #13625
This should also probably be backported as this is common problem, and could explain
quarto previewlock issue in positron (which I think use--output-dirfor some files)