Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ignore links (symlinks/hardlinks)#4755

Open
divinity76 wants to merge 2 commits intophan:v5from
divinity76:patch-1
Open

Ignore links (symlinks/hardlinks)#4755
divinity76 wants to merge 2 commits intophan:v5from
divinity76:patch-1

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.

2 participants