Repository navigation
fix(common): follow symlinked directories when scanning font directories on Linux - #320
Conversation
juliusknorr
left a comment
There was a problem hiding this comment.
Thanks a lot for your contribution and the thorough tests.
CI is failing, could you have a look at that still?
- Build, all three Linux jobs:
test_odfandodf_regression_testcrash with a segfault. Both pass on main, so the failure looks related. - Build (macOS arm64):
directory_testfails insymlinked_file_is_listed. - Conventional commits: neither the PR title nor the commit message is a conventional commit.
|
I think leaving out macOS and Windows is reasonable for a first iteration. 👍 |
e450e98 to
8c19705
Compare
|
Renamed the PR so the conventional-commits check passes. The Android arm64 build that failed earlier was a runner timeout, it passed on a re-run. CI is green now 👍 |
juliusknorr
left a comment
There was a problem hiding this comment.
One thing before this can be merged: the loop check only catches a link to the folder itself. A link to a parent folder (e.g. fonts/sub/up -> ..) is still followed until the kernel's symlink limit, which makes the listing about 41 times larger, and two such links run out of memory. Since the font scan now follows links, a single unusual symlink in a font folder could make font generation hang or crash, where today the font is only missing.
For the coding task this is fine as it is, you already list it as a limitation. For merging we'd need it fixed though.
readdir() reports a symlink as DT_LNK. The POSIX listing loop in NSDirectory::GetFiles2() classified only DT_REG, DT_DIR and DT_UNKNOWN, so DT_LNK entries fell through unclassified and were dropped. Fonts installed as symlinks were therefore never picked up — the symptom reported in Euro-Office#128, which hits NixOS hardest because its font directories are largely symlinks into the store, but which also affects a symlinked font in ~/.local/share/fonts on Ubuntu. DT_LNK now goes through stat(), which follows the link, so the target decides. Only regular-file targets are listed. Symlinked directories are deliberately left unclassified: DeleteDirectory() is built on GetFiles()/GetDirectories() and recurses over what they return, so reporting a symlinked directory would make it delete the link target's contents instead of just removing the link. A directory symlink passed to GetFiles() directly is unaffected — opendir() follows it — so the common case of a font directory that is itself a symlink keeps working. Adds DesktopEditor/common/test, a new GoogleTest suite registered with CTest. It builds its tree at run time (regular file, symlink to it, dangling symlink, self-referencing symlink), so no fixtures are committed. The suite covers the fix and pins the deliberate limitation: one case fails if a future change starts following directory symlinks. Verified on Linux by removing the fix and restoring it: without it the suite reports exactly one failure (symlinked_file_is_listed — "link.bin" missing), with it 5/5 pass, repeatably. The other built CTest suites still pass. Known, not addressed here: the MAC/_IOS variants of these loops have the same gap and additionally lack the DT_UNKNOWN fallback, and CopyDirectory() likewise skips symlinked files. Neither is testable on this machine. Signed-off-by: Krzysztof Cieślik <132496025+Hathor875@users.noreply.github.com> Assisted-by: Claude Code:claude-opus-5 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Add a new API call GetFilesFollowSymlinks that acts like GetFiles2, but follows symlink directories. Switch fontengine to use the new API call instead of GetFiles2. Implementation limitations: * Only implemented for Linux * It guards against linked directory recursion, but only if the directory points to itself * There is no deduplication of file list: files may be listed multiple times, when accessed via different paths Assisted-by: ClaudeCode:claude-sonnet-5-5 Signed-off-by: Ivan Sherov-Ignatev <sherov@gmail.com>
* Move empty directory check downwards to cover all three API functions * Add tests for the empty directory cases * Add build guards for the directory tests Assisted-by: ClaudeCode:claude-sonnet-5-5 Signed-off-by: Ivan Sherov-Ignatev <sherov@gmail.com>
2ebb0e2 to
6550f1a
Compare
Previous solution allowed for symlink cycles, which could make font generation hang or crash Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ivan Sherov-Ignatev <sherov@gmail.com>
|
@juliusknorr I added guards against the symlink directory recursion, and the PR is ready for review |
chrip
left a comment
There was a problem hiding this comment.
Request changes. The new test file needs a license header. After that and a re-run of the cancelled checks, this is good to merge from my side.
This PR makes the font scan follow symlinked folders on Linux, with a guard against loops. I tested the guard with a small program built from GetFilesLinux: a link to the folder itself, to its parent, to its grandparent, two folders linking to each other and a dangling link all end cleanly. The design looks right to me, and the tests cover the cases I would have asked for.
Earlier comments:
- @juliusknorr: a link to a parent folder is followed until the kernel's symlink limit: fixed ✓. The scan now skips any link back into a folder on the current path.
- @juliusknorr:
test_odfandodf_regression_testcrash on Linux,directory_testfails on macOS, commit messages: addressed ✓ - @juliusknorr: debugging leftover comment in
Directory.cpp: removed ✓
The required checks have not finished on this commit. The Android and rocky8 amd64 builds were cancelled after about ten hours without a runner, and build-wasm failed while cloning OpenSSL from GitHub (could not read Username for 'https://github.com'). This PR didn't cause any of that; the jobs need a re-run.
issue (blocking): DesktopEditor/common/test/main.cpp is a new file without a license header.
Please add the header that systemutils_test.cpp next to it uses:
/*
* SPDX-FileCopyrightText: 2026 Euro-Office contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
suggestion: Remember every folder the scan has opened, not only the ones on the current path.
DesktopEditor/common/Directory.cpp:101 keeps the chain of parent folders and drops each entry on the way out (line 185), so a folder reachable through several links is walked once per path. That is the duplicate listing you mention as a limitation, and it grows fast. In a test tree of 9 folders where each one links to the other 8, the scan returns 986,409 entries for 9 font files and takes 17 seconds; with 8 folders it was 109,600 entries. A std::set of (st_dev, st_ino) kept for the whole scan and checked before each folder is read would list every folder once, which removes the duplicates and the growth. CFontList::Add already drops duplicate fonts by name, so the extra entries only cost time and memory. That's why I don't block on this.
This PR also carries the commit from #136. Once this one is merged, #136 can be closed.
Assisted-by: ClaudeCode:claude-opus-5-5
Duplicate listing with several nested symlinks led to excessive memory and time consumption Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ivan Sherov-Ignatev <sherov@gmail.com>
Thank you, both issues fixed |
juliusknorr
left a comment
There was a problem hiding this comment.
Thanks, the set of visited folders looks good and also covers the parent link case from my earlier review 👍 License header is in as well. I ran a 9-folder tree where every folder links to every other one through the new code: 9 files listed once, in a few ms.
Not a blocker: the visited set only lives for one call, so if one of the font roots links into another (e.g. /usr/local/share/fonts into /usr/share/fonts), those files are still listed twice. Same as before, and CFontList::Add drops duplicates anyway.
The follow-up commits could be squashed into one, but we can do that when merging.
chrip
left a comment
There was a problem hiding this comment.
Approve. Looks good to merge.
My earlier review:
- license header in
DesktopEditor/common/test/main.cpp: fixed ✓ - keep a set of visited folders for the whole scan: done ✓, with new tests for it
- the cancelled Android,
rocky8 amd64and WASM checks: all pass on this commit ✓
Assisted-by: ClaudeCode:claude-opus-5-5
What
Added on top of #136
Addresses issue #128 for Linux.
Added a new API call GetFilesFollowSymlinks that acts like GetFiles2, but follows symlink directories.
Switched fontengine to use the new API call instead of GetFiles2.
Implementation limitations:
Possible next steps:
Tests
Added appropriate unit tests for Linux, covering basic use cases and edge cases
AI-assisted, see Assisted-by trailer.