Repository navigation
fix: resolve symlinks in safeRemoveDirSync to fix cleanup with symlinked paths - #13894
Conversation
…ked paths Fixes rendering with `embed-resources: true` when the input path goes through a symlinked directory.
✅ 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. |
|
I think I got the understanding right, but the resolution wrong looking at commit history... I see f9cdaa9 with message So it seems we don't want to use Like this happens with knitr. So I assumed we needed that. @cscheid Do you remember the history behind f9cdaa9 ? I assumed maybe comestic to avoid having some Initially the monkey was done because of denoland/deno#12243 and I confirmed locally that the deno version we used solves this. This PR change is scoped in the sense we do use but maybe we don't need to monkey-path after all the deno std itself. Anyhow, I know you're on other focus, but it feels having another dev look would help me confirm my initial fix. |
When rendering a
.qmddocument withembed-resources: trueusing an absolute path through a symlinked directory, the render fails during cleanup with:Root Cause
The path mismatch occurs in this sequence:
/home/c/cr173/tmp/quarto-bug/test.qmdproject.dirkeeps the symlink path (Quarto'snormalizePath()does NOT resolve symlinks)rmarkdown:::abs_path(intermediates_dir)calls R'snormalizePath()which DOES resolve symlinks/home/vis/cr173/tmp/quarto-bug/test_filessafeRemoveDirSync()compares these paths as strings, which failsThe knitr symlink resolution happens in
src/resources/rmd/execute.R:The deeper issue is that
src/core/deno/monkey-patch.tsreplacesDeno.realPathSyncwithnormalizePath, which intentionally does NOT resolve symlinks. This was done in commit3bb0b45dc(Aug 2022) to work around a Windows UNC path bug whereDeno.realPathSyncreturned malformed paths likeUNC\x.org\...instead of\\x.org\....That UNC bug was fixed in Deno v1.16 (denoland/deno#12243). Quarto now uses Deno 2.3.1+, so the original workaround is no longer needed.
Fix
Rather than removing the monkey-patch globally (which would require auditing all code paths), this fix:
src/deno_ral/original-real-path.tsthat saves the originalDeno.realPathSyncbefore monkey-patchingsrc/quarto.tsBEFORE the monkey-patch importsafeRemoveDirSync()to resolve both paths using the originalrealPathSyncbefore comparisonThe separate module with no imports avoids circular dependencies:
This is a targeted fix that only affects the safety boundary check, with fallback to original paths if resolution fails.
Testing
tests/unit/ral/safe-remove-dir.test.tsfor symlink handlingtests/smoke/render/render-symlink-embed-resources.test.tsFollow-up Consideration
Since the UNC bug was fixed in Deno v1.16 (2021), and Quarto now uses Deno 2.3.1+, the monkey-patch may no longer be necessary at all. A follow-up issue could review whether the monkey-patch can be removed entirely, which would restore proper symlink resolution globally.
References:
Fixes #13890