Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.4.2

Bug #18072 Impossible to exclude path from processing when symlinked
Submitted: 2010-11-18 22:16 UTC
From: glen Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.0RC1)
PHP Version: 5.3.3 OS: PLD Linux
Roadmaps: (Not assigned)    
Subscription  


 [2010-11-18 22:16 UTC] glen (Elan Ruusamäe)
Description: ------------ It is impossible to exclude path from processing. I need to skip processing path that i contains files i can't access. Test script: --------------- glen@wintersunset trunk/test $ cat phpcs.xml <?xml version="1.0"?> <ruleset name="Eventum"> <description>Eventum coding standard.</description> <exclude-pattern>*/config/*</exclude-pattern> <rule ref="Generic.PHP.DisallowShortOpenTag"/> </ruleset> glen@wintersunset trunk/test $ ls -lR .: total 4 drwxr-xr-x 2 glen glen 61 2010-10-07 15:08 config/ -rw-r--r-- 1 glen glen 206 2010-11-18 18:13 phpcs.xml ./config: total 0 lrwxrwxrwx 1 glen glen 31 2010-11-18 18:12 config.php -> /etc/webapps/eventum/config.php lrwxrwxrwx 1 glen glen 36 2010-11-18 18:12 private_key.php -> /etc/webapps/eventum/private_key.php lrwxrwxrwx 1 glen glen 30 2010-11-18 18:12 setup.php -> /etc/webapps/eventum/setup.php glen@wintersunset trunk/test $ Expected result: ---------------- as you can see, i've excluded */config/* from processing, but it still processes them and results fatal error Actual result: -------------- glen@wintersunset trunk/test $ phpcs --standard=phpcs.xml . PHP Warning: fopen(/etc/webapps/eventum/config.php): failed to open stream: Permission denied in /usr/share/pear/PHP/CodeSniffer.php on line 984 PHP Stack trace: PHP 1. {main}() /usr/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:38 PHP 3. PHP_CodeSniffer->process() /usr/share/pear/PHP/CodeSniffer/CLI.php:494 PHP 4. PHP_CodeSniffer->processFiles() /usr/share/pear/PHP/CodeSniffer.php:435 PHP 5. PHP_CodeSniffer->processFile() /usr/share/pear/PHP/CodeSniffer.php:913 PHP 6. fopen() /usr/share/pear/PHP/CodeSniffer.php:984 PHP Warning: fopen(/etc/webapps/eventum/config.php): failed to open stream: Permission denied in /usr/share/pear/PHP/CodeSniffer/File.php on line 570 PHP Stack trace: PHP 1. {main}() /usr/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:38 PHP 3. PHP_CodeSniffer->process() /usr/share/pear/PHP/CodeSniffer/CLI.php:494 PHP 4. PHP_CodeSniffer->processFiles() /usr/share/pear/PHP/CodeSniffer.php:435 PHP 5. PHP_CodeSniffer->processFile() /usr/share/pear/PHP/CodeSniffer.php:913 PHP 6. PHP_CodeSniffer->_processFile() /usr/share/pear/PHP/CodeSniffer.php:1001 PHP 7. PHP_CodeSniffer_File->start() /usr/share/pear/PHP/CodeSniffer.php:1087 PHP 8. PHP_CodeSniffer_File->_parse() /usr/share/pear/PHP/CodeSniffer/File.php:376 PHP 9. PHP_CodeSniffer_File::detectLineEndings() /usr/share/pear/PHP/CodeSniffer/File.php:516 PHP 10. fopen() /usr/share/pear/PHP/CodeSniffer/File.php:570 FILE: /etc/webapps/eventum/config.php -------------------------------------------------------------------------------- FOUND 1 ERROR(S) AFFECTING 1 LINE(S) -------------------------------------------------------------------------------- 1 | ERROR | An error occurred during processing; checking has been aborted. | | The error message was: Error opening file; could not auto-detect | | line endings -------------------------------------------------------------------------------- glen@wintersunset trunk/test $

Comments

 [2010-11-19 07:18 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
I can't replicate this issue. Can you please try running: phpcs --standard=phpcs.xml . -v to produce a list of checked files and make sure the file is actually still being checked (it must be) Or maybe even a summary report to check the full file paths: phpcs --standard=phpcs.xml . -v --report=summary --report-width=150 (width should be however long you need to fit the paths in) Then try putting the ignore pattern onto the command line, like this: phpcs --standard=phpcs.xml . -v --ignore=*/config/*
 [2010-12-16 04:50 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: No Feedback
 [2010-12-16 15:49 UTC] glen (Elan Ruusamäe)
as a quick note, before running your suggested tests: i forgot to mention that the symlinks point to directory which i have no access to, i.e chmod 000 /etc/webapps
 [2010-12-16 16:10 UTC] glen (Elan Ruusamäe)
the reports i hope they help you track down where the symlink follow should be turned off $ phpcs --standard=phpcs.xml . -v --report=summary --report-width=150 Registering sniffs in Eventum standard... DONE (1 sniffs registered) PHP Warning: fopen(/etc/webapps/eventum/config.php): failed to open stream: Permission denied in /usr/share/pear/PHP/CodeSniffer.php on line 1031 PHP Stack trace: PHP 1. {main}() /usr/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:38 PHP 3. PHP_CodeSniffer->process() /usr/share/pear/PHP/CodeSniffer/CLI.php:508 PHP 4. PHP_CodeSniffer->processFiles() /usr/share/pear/PHP/CodeSniffer.php:461 PHP 5. PHP_CodeSniffer->processFile() /usr/share/pear/PHP/CodeSniffer.php:955 PHP 6. fopen() /usr/share/pear/PHP/CodeSniffer.php:1031 Processing config.php PHP Warning: fopen(/etc/webapps/eventum/config.php): failed to open stream: Permission denied in /usr/share/pear/PHP/CodeSniffer/File.php on line 616 PHP Stack trace: PHP 1. {main}() /usr/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:38 PHP 3. PHP_CodeSniffer->process() /usr/share/pear/PHP/CodeSniffer/CLI.php:508 PHP 4. PHP_CodeSniffer->processFiles() /usr/share/pear/PHP/CodeSniffer.php:461 PHP 5. PHP_CodeSniffer->processFile() /usr/share/pear/PHP/CodeSniffer.php:955 PHP 6. PHP_CodeSniffer->_processFile() /usr/share/pear/PHP/CodeSniffer.php:1048 PHP 7. PHP_CodeSniffer_File->start() /usr/share/pear/PHP/CodeSniffer.php:1134 PHP 8. PHP_CodeSniffer_File->_parse() /usr/share/pear/PHP/CodeSniffer/File.php:383 PHP 9. PHP_CodeSniffer_File::detectLineEndings() /usr/share/pear/PHP/CodeSniffer/File.php:562 PHP 10. fopen() /usr/share/pear/PHP/CodeSniffer/File.php:616 PHP CODE SNIFFER REPORT SUMMARY ------------------------------------------------------------------------------------------------------------------------------------------------------ FILE ERRORS WARNINGS ------------------------------------------------------------------------------------------------------------------------------------------------------ /etc/webapps/eventum/config.php 1 0 ------------------------------------------------------------------------------------------------------------------------------------------------------ A TOTAL OF 1 ERROR(S) AND 0 WARNING(S) WERE FOUND IN 1 FILE(S) ------------------------------------------------------------------------------------------------------------------------------------------------------ $ phpcs --standard=phpcs.xml . -v --ignore=*/config/* Registering sniffs in Eventum standard... DONE (1 sniffs registered) PHP Warning: fopen(/etc/webapps/eventum/config.php): failed to open stream: Permission denied in /usr/share/pear/PHP/CodeSniffer.php on line 1031 PHP Stack trace: PHP 1. {main}() /usr/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:38 PHP 3. PHP_CodeSniffer->process() /usr/share/pear/PHP/CodeSniffer/CLI.php:508 PHP 4. PHP_CodeSniffer->processFiles() /usr/share/pear/PHP/CodeSniffer.php:461 PHP 5. PHP_CodeSniffer->processFile() /usr/share/pear/PHP/CodeSniffer.php:955 PHP 6. fopen() /usr/share/pear/PHP/CodeSniffer.php:1031 Processing config.php PHP Warning: fopen(/etc/webapps/eventum/config.php): failed to open stream: Permission denied in /usr/share/pear/PHP/CodeSniffer/File.php on line 616 PHP Stack trace: PHP 1. {main}() /usr/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:38 PHP 3. PHP_CodeSniffer->process() /usr/share/pear/PHP/CodeSniffer/CLI.php:508 PHP 4. PHP_CodeSniffer->processFiles() /usr/share/pear/PHP/CodeSniffer.php:461 PHP 5. PHP_CodeSniffer->processFile() /usr/share/pear/PHP/CodeSniffer.php:955 PHP 6. PHP_CodeSniffer->_processFile() /usr/share/pear/PHP/CodeSniffer.php:1048 PHP 7. PHP_CodeSniffer_File->start() /usr/share/pear/PHP/CodeSniffer.php:1134 PHP 8. PHP_CodeSniffer_File->_parse() /usr/share/pear/PHP/CodeSniffer/File.php:383 PHP 9. PHP_CodeSniffer_File::detectLineEndings() /usr/share/pear/PHP/CodeSniffer/File.php:562 PHP 10. fopen() /usr/share/pear/PHP/CodeSniffer/File.php:616 FILE: /etc/webapps/eventum/config.php -------------------------------------------------------------------------------- FOUND 1 ERROR(S) AFFECTING 1 LINE(S) -------------------------------------------------------------------------------- 1 | ERROR | An error occurred during processing; checking has been aborted. | | The error message was: Error opening file; could not auto-detect | | line endings --------------------------------------------------------------------------------
 [2010-12-17 04:15 UTC] squiz (Greg Sherwood)
-Status: No Feedback +Status: Open
 [2010-12-17 04:34 UTC] squiz (Greg Sherwood)
Based on the output of your run, you don't want the filter to be /config/* You need the filter to be something like */config.php But I still think there is room to improve PHPCS here by doing perm checks on the files and reporting the error rather than allowing the warning to be shown. I'll take a look into that.
 [2010-12-17 07:09 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Closed
I've committed some changes so that you no longer get PHP warnings and the script wont stop if it finds a permission problem. Instead, for each file you don't have access to, you'll get a warning in the report, like this: 1 | WARNING | Error opening file; file no longer exists or you do not have access to read the file
 [2010-12-20 15:31 UTC] glen (Elan Ruusamäe)
ok, excluding by filename worked: glen@wintersunset phpcs/bug-18072 $ phpcs --standard=phpcs.xml . -v --ignore=*/config.php,*/private_key.php,*/setup.php Registering sniffs in Eventum standard... DONE (1 sniffs registered) but i really need path based exclusion (i.e exclude a dir), as i could have setup.php elsewhere in project tree which i don't want to exclude.
 [2010-12-20 16:24 UTC] squiz (Greg Sherwood)
PHPCS does regular expression matching. You can exclude dirs or files, but your files are not in a /config dir (or at least the one throwing the error). You pasted a file path like: /etc/webapps/eventum/config.php So if you want an exclude rule to exclude that whole directory, your exclude rule would be: */eventum/*
 [2010-12-20 20:14 UTC] glen (Elan Ruusamäe)
sorry for the spam, but i have feeling there's some misunderstanding. my files are in ./config/ dir, they just are symlinks [1] to elsewhere, i want to blacklist by the original files not by path they point to, because i can't be knowing all possible locations they would point to, and i want the exclude rule be independant of who has checked out the project code. [1] http://en.wikipedia.org/wiki/Symbolic_link
 [2010-12-21 04:38 UTC] squiz (Greg Sherwood)
-Status: Closed +Status: Open
Sorry, I missed the symlink part from the original comment. Will check it out again.
 [2010-12-21 05:44 UTC] squiz (Greg Sherwood)
-Summary: Impossible to exclude path from processing +Summary: Impossible to exclude path from processing when symlinked -Status: Assigned +Status: Closed
The real problem here was that the ignore patterns were being checked after realpath() was called on the file path, so it was checking ignore patterns on path to the original file and not the path to the symlink. I've now corrected this in SVN. The one place where this still wont work is if the directory you are passing to PHP_CodeSniffer is actually a symlink itself. I call realpath() of the file paths passed on the command line to both ensure they exist and to ensure all ./ and ../ refs are replaced before processing.