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
is_link does not work correct under php with windows #34
Comments
There are some comments regarding Windows in the manual: http://php.net/is_link
|
@leofeyer I have tried this, but there was no difference which I can handle. I tried the following and this works pretty well: $linkReal = 'D:\\www\\contao-3.3.5\\system\\modules\\!composer'; // Symbolic link
$targetReal= 'D:\\www\\contao-3.3.5\\composer\\vendor\\contao-community-alliance\\composer-client'; // real folder
if (defined('PHP_WINDOWS_VERSION_BUILD') && readlink($linkReal) == $targetReal) {
// is_link
}
Only Problem: Any other suggestions are welcome. :D |
I have added a PR. Please check if the current behaviour is still working ;) |
The bug report says:
Did you check whether your symlinks show up as
According to this comment, there is an "array_diff trick" to work around the issue. However, you are using |
I think its all from the bug report: https://bugs.php.net/bug.php?id=65697 The "array_diff trick" is shown in the initial comment: foreach ( $paths as $path )
{
echo "----\n $path\n";
var_dump( is_link( $path ) );
var_dump( is_dir( $path ) );
var_dump( array_diff( stat($path), lstat($path) ) );
} I expect |
That's exactly my concern, too. |
No I haven't. Will check this later. |
So I have checked it again to be save ;)
Now I have ;) Folders are point out as So if you won't prefer the readlink solution I can check the stat / lstat solution. |
And what happen, if the link is outdated or manipulated? |
@tristanlins you are right. I only check if the symbolic link is valid. I have missed this. The Checks are running under Windows 8.1 Xampp, PHP 5.5.15 So I have made same tests for $link = "D:\\www\\contao-3.3.5\\system\\modules\\!composer"; // Symbolic link
var_dump(array_diff(stat($link), lstat($link)));
$link2 = "D:\\www\\contao-3.3.5\\system\\modules"; // real folder
var_dump(array_diff(stat($link2), lstat($link2)));
So, there should be a differenz when I get it right, but there isn't. So with the hint from @tristanlins I would propose the following: public static function isSymbolicLink($target)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if(file_exists($target) && readlink($target) != $target) {
return true;
}
} elseif (is_link($target)) {
return true;
}
return false;
} So I think it is enough to check against the target |
Small note https://github.com/symfony/Filesystem/blob/master/Filesystem.php#L287 Idea: Use the Symfony Filesystem. @discordier ? |
Sry to say that, but plugins should not depend on any other library. |
I am with @tristanlins on this one. A plugin must be independent from other packages. |
@tristanlins @discordier ok. That's no problem. Btw. I have looked deeper in the Filesystem class and methods. And there is no |
The typo3 flow guys using |
$realpath = realpath($target);
if ($realpath !== $target) {
// It is a symlink
return true;
}
// fallback for broken symlinks
$link = readlink($target);
if ($link && $link !== $target) {
// It is a broken symlink
return true;
}
return false; |
@tristanlins Sounds interresting I will check this. |
If I rethink my code, the fallback may be wrong / unnecessary. |
Hm. So to do the same as PHP Doc from
If I understand right: a broken symlink is a symlink without a target. But does it return true or false then? |
@tristanlins I have checked your code and it doesn't work correctly. $realpath = realpath($target);
if ($realpath !== $target) {
// It is a symlink
return true;
} If target is a Folder So changing the if clause to if ($realpath && $realpath !== $target) everything works like expected. Next Problem |
This is absolutely correct, because a broken link is still a link. |
Are you sure about that? In my testing |
I think that this is also resolved by using php-fcgi on xampp: |
The Problem is, that the
is_link
returns alwaysfalse
.That is realy weird. So I haven't found a usefull solution for now. Any Ideas?
The text was updated successfully, but these errors were encountered: