Skip to content

Commit

Permalink
Fixed an issue that could occurr when checking files on network drive…
Browse files Browse the repository at this point in the history
…s (ref #2965)
  • Loading branch information
gsherwood committed Oct 30, 2020
1 parent 0e183a5 commit d56e167
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Files/LocalFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LocalFile extends File
public function __construct($path, Ruleset $ruleset, Config $config)
{
$this->path = trim($path);
if (is_readable($this->path) === false) {
if (Common::isReadable($this->path) === false) {
parent::__construct($this->path, $ruleset, $config);
$error = 'Error opening file; file no longer exists or you do not have access to read the file';
$this->addMessage(true, $error, 1, 1, 'Internal.LocalFile', [], 5, false);
Expand Down
28 changes: 28 additions & 0 deletions src/Util/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ public static function isPharFile($path)
}//end isPharFile()


/**
* Checks if a file is readable.
*
* Addresses PHP bug related to reading files from network drives on Windows.
* e.g. when using WSL2.
*
* @param string $path The path to the file.
*
* @return boolean
*/
public static function isReadable($path)
{
if (is_readable($path) === true) {
return true;
}

if (file_exists($path) === true && is_file($path) === true) {
$f = @fopen($path, 'rb');
if (fclose($f) === true) {
return true;
}
}

return false;

}//end isReadable()


/**
* CodeSniffer alternative for realpath.
*
Expand Down

0 comments on commit d56e167

Please sign in to comment.