-
Notifications
You must be signed in to change notification settings - Fork 387
Fix Windows file locking error when rendering with --output-dir #13626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cderv
wants to merge
8
commits into
main
Choose a base branch
from
windows/file-lock-issue-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−9
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
When --output-dir is used without a project file, Quarto creates a synthetic project context with a temporary .quarto directory to manage the render. This fix ensures file handles are closed before attempting to remove the directory, preventing Windows "os error 32" (file in use by another process). The synthetic project pattern: - Triggered when: quarto render file.qmd --output-dir output/ (no _quarto.yml) - Creates temporary .quarto directory in current directory - Uses full renderProject() path (not singleFileProjectContext()) - forceClean flag in RenderOptions signals cleanup needed - After render: close handles (context.cleanup()) then remove directory Improved comments to explain the synthetic project pattern, the dual purpose of the forceClean flag, and critical ordering requirements to avoid file locking issues on Windows. Fixes #13625
802c001 to
548f6af
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)