Skip to content

fix: infinite loop caused by symbolic links pointing to ancestor directories - #120

Merged
fortmarek merged 5 commits into
tuist:mainfrom
monchote:fix-symlink-relative-infinite-loop
Apr 25, 2025
Merged

fix: infinite loop caused by symbolic links pointing to ancestor directories#120
fortmarek merged 5 commits into
tuist:mainfrom
monchote:fix-symlink-relative-infinite-loop

Conversation

@monchote

Copy link
Copy Markdown
Contributor

The issue

Repositories like GRDB that contain a relative symbolic link that point to a parent directory (see example) can cause an infinite loop when running tuist generate:

Fetching groue.GRDB_swift from cache
Fetched groue.GRDB_swift from cache (0.52s)
Loading and constructing the graph
It might take a while if the cache is empty
2025-04-23 21:29:36.639 tuist[70125:8131301] CFURLCopyResourcePropertyForKey failed because it was passed a URL which has no scheme
2025-04-23 21:29:36.707 tuist[70125:8131301] CFURLCopyResourcePropertyForKey failed because it was passed a URL which has no scheme
2025-04-23 21:29:36.707 tuist[70125:8131301] CFURLCopyResourcePropertyForKey failed because it was passed a URL which has no scheme
2025-04-23 21:29:36.707 tuist[70125:8131301] CFURLCopyResourcePropertyForKey failed because it was passed a URL which has no scheme
2025-04-23 21:29:36.707 tuist[70125:8131301] CFURLCopyResourcePropertyForKey failed because it was passed a URL which has no scheme
2025-04-23 21:29:36.707 tuist[70125:8131301] CFURLCopyResourcePropertyForKey failed because it was passed a URL which has no scheme
We received an error that we couldn't handle:
    - Localized description: The file “Documentation” couldn’t be opened.
    - Error: Error Domain=NSCocoaErrorDomain Code=256 "The file “Documentation” couldn’t be opened." UserInfo={NSURL=/Users/ramonarguello/src/github.com/monzo/ios-app/Tuist/.build/registry/downloads/groue/GRDB_swift/7.4.1/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Documentation, NSFilePath=/Users/ramonarguello/src/github.com/monzo/ios-app/Tuist/.build/registry/downloads/groue/GRDB_swift/7.4.1/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Tests/CustomSQLite/GRDB/Documentation, NSUnderlyingError=0x600002e0acd0 {Error Domain=NSPOSIXErrorDomain Code=62 "Too many levels of symbolic links"}}
Consider creating an issue using the following link: https://github.com/tuist/tuist/issues/new/choose

The fix

The fix is to not visit any symbolic links that point to an ancestor path of the current path. To make sure all symbolic links in the paths are resolved when comparing paths, canonicalPathKey are read and used.

Testing

A test that reproduces the issue is also provided.

The fix has also been tested running tuist from source with the FileSystem dependency pointing to this branch.

@monchote monchote changed the title Fix infinite loop caused by symbolic links pointing to ancestor directories fix: Fix infinite loop caused by symbolic links pointing to ancestor directories Apr 24, 2025
@monchote monchote changed the title fix: Fix infinite loop caused by symbolic links pointing to ancestor directories fix: infinite loop caused by symbolic links pointing to ancestor directories Apr 24, 2025
@pepicrft
pepicrft requested review from Copilot and fortmarek April 24, 2025 13:44

Copilot AI 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.

Pull Request Overview

This PR addresses an infinite loop issue caused by symbolic links pointing to ancestor directories by preventing the traversal of these links during the glob search. Key changes include adding a new test in FileSystemTests to reproduce the issue, modifying the search function in GlobSearch to skip directories that match the ancestor condition, and introducing the helper function pathHasAncestor to compare resolved canonical paths.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Tests/FileSystemTests/FileSystemTests.swift Added a test to verify that symbolic links pointing to ancestor directories are safely skipped
Sources/Glob/GlobSearch.swift Updated the search logic to prevent infinite loops by checking against ancestor directories using resolved canonical paths

Comment thread Sources/Glob/GlobSearch.swift Outdated
@monchote
monchote requested a review from pepicrft April 24, 2025 18:05
@pepicrft

Copy link
Copy Markdown
Contributor

Let's wait to get @fortmarek's input on this one.

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

Looks great, thanks!

@fortmarek
fortmarek merged commit 5dbbe86 into tuist:main Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants