Skip to content

fix(common): follow symlinked directories when scanning font directories on Linux - #320

Merged
juliusknorr merged 5 commits into
Euro-Office:mainfrom
sherov:symlink-files
Dec 4, 2026
Merged

juliusknorr merged 5 commits into
Euro-Office:mainfrom
sherov:symlink-files

Conversation

@sherov

@sherov sherov commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Only implemented for Linux
  • There is no deduplication of file list, but it is minimized by avoiding re-listing of the same directory via different paths

Possible next steps:

  • Implement for MacOS

Tests

Added appropriate unit tests for Linux, covering basic use cases and edge cases

AI-assisted, see Assisted-by trailer.

@juliusknorr juliusknorr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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_odf and odf_regression_test crash with a segfault. Both pass on main, so the failure looks related.
  • Build (macOS arm64): directory_test fails in symlinked_file_is_listed.
  • Conventional commits: neither the PR title nor the commit message is a conventional commit.

Comment thread DesktopEditor/common/Directory.cpp Resolved
@juliusknorr

Copy link
Copy Markdown
Member

I think leaving out macOS and Windows is reasonable for a first iteration. 👍

@juliusknorr juliusknorr added the bug Something isn't working label Nov 16, 2026
@sherov
sherov force-pushed the symlink-files branch 3 times, most recently from e450e98 to 8c19705 Compare November 16, 2026 17:36
@sherov
sherov requested a review from juliusknorr November 17, 2026 12:39
@juliusknorr juliusknorr changed the title Follow symlinked directories when scanning font directories on Linux fix: Follow symlinked directories when scanning font directories on Linux Nov 17, 2026
@juliusknorr juliusknorr changed the title fix: Follow symlinked directories when scanning font directories on Linux fix(common): follow symlinked directories when scanning font directories on Linux Nov 19, 2026
@juliusknorr

Copy link
Copy Markdown
Member

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 juliusknorr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@juliusknorr juliusknorr moved this from 📄 To do to 🏗️ In progress in 📄 Euro-Office team Dec 1, 2026
Hathor875 and others added 3 commits December 1, 2026 16:52
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>
@sherov
sherov force-pushed the symlink-files branch 2 times, most recently from 2ebb0e2 to 6550f1a Compare December 2, 2026 10:36
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>
@sherov
sherov marked this pull request as ready for review December 2, 2026 10:55
@sherov
sherov requested a review from a team as a code owner December 2, 2026 10:55
@sherov
sherov requested review from DmySyz and chrip and removed request for a team December 2, 2026 10:55
@sherov

sherov commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@juliusknorr I added guards against the symlink directory recursion, and the PR is ready for review

@sherov
sherov requested a review from juliusknorr December 2, 2026 10:58
@sherov sherov moved this from 🏗️ In progress to 👀 In review in 📄 Euro-Office team Dec 2, 2026

@chrip chrip 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.

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_odf and odf_regression_test crash on Linux, directory_test fails 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

@github-project-automation github-project-automation Bot moved this from 👀 In review to 🏗️ In progress in 📄 Euro-Office team Dec 3, 2026
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>
@sherov

sherov commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

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.

Thank you, both issues fixed

@sherov
sherov requested a review from chrip December 4, 2026 08:31
@sherov sherov moved this from 🏗️ In progress to 👀 In review in 📄 Euro-Office team Dec 4, 2026

@juliusknorr juliusknorr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 chrip 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.

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 amd64 and WASM checks: all pass on this commit ✓

Assisted-by: ClaudeCode:claude-opus-5-5

@juliusknorr
juliusknorr merged commit cf011b7 into Euro-Office:main Dec 4, 2026
28 checks passed
@github-project-automation github-project-automation Bot moved this from 👀 In review to ☑️ Done in 📄 Euro-Office team Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: ☑️ Done

Development

Successfully merging this pull request may close these issues.

4 participants