Skip to content
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

Ignore links (symlinks/hardlinks) #4755

Open
wants to merge 2 commits into
base: v5
Choose a base branch
from
Open

Conversation

divinity76
Copy link

I use symlinks in my projects to open the same file in multiple tabs in VSCode ( ref https://stackoverflow.com/a/73994770/1067003 for why i need to use symlinks),
which causes Phan to crash like

$ ./vendor/bin/phan
ERROR: Unable to read file /home/hans/projects/easyad/classes/Controller/System/VitecBooking.2ln.php: SplFileInfo->isFile() is false for SplFileInfo->getType() == 'link'

the easy fix is to just ignore links.

I use symlinks in my projects to open the same file in multiple tabs in VSCode ( ref https://stackoverflow.com/a/73994770/1067003 for why i need to use symlinks), 
which causes Phan to crash like

$ ./vendor/bin/phan
ERROR: Unable to read file /home/hans/projects/easyad/classes/Controller/System/VitecBooking.2ln.php: SplFileInfo->isFile() is false for SplFileInfo->getType() == 'link'


the easy fix is to just ignore links.
@TysonAndre
Copy link
Member

I have projects set up that rely on symlinks (e.g. where multiple applications depend on the same library as a symlinked folder)

It'd be better to have this as a .phan/config.php setting such as 'ignore_symlinks' defaulting to false (see src/Phan/Config.php)

@divinity76
Copy link
Author

divinity76 commented Mar 12, 2023

@TysonAndre well my only problem was that phan crashed when encountering the link. i actually wouldn't mind if phan would follow the link instead of ignoring it.

assuming nobody actually need links to be ignored, do you think we could just do a

                    while ($file_info->isLink()) {
                        // follow links
                        $file_info = new SplFileInfo($file_info->getLinkTarget());
                    }

? perhaps with a max-follow-link thing to protect against infinite link-to-link loop, which would cause the code above to hang - sounds like an extremely rare edge-case, but still, perhaps

                    $link_counter=0;
                    while ($file_info->isLink()) {
                        // follow links
                        $file_info = new SplFileInfo($file_info->getLinkTarget());
                        if(++$link_counter >= 100) {
                            throw new \RuntimeException("infinite link loop");
                        }
                    }

edit: the code above might be incorrect, seems one should use SplFileInfo::getRealPath instead of SplFileInfo::getLinkTarget

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.

None yet

2 participants