Skip to content

Commit 68293b1

Browse files
committed
Enable symlink_link_linkinfo_is_link_* tests on Windows
We mark symlink_link_linkinfo_is_link_error2.phpt as XFAIL on Windows ZTS. Several Windows API file system functions ignore trailing spaces in absolute filenames after the final directory separator, which causes `link(' ', $link)` to actually call `CreateHardLink()` which then fails, because linking folders is not supported. However, with NTS builds (as well as on other systems), the $target is found to not exist, so the function fails without actually attempting to create the link. This needs further investigation.
1 parent b291c92 commit 68293b1

13 files changed

+74
-68
lines changed

ext/standard/tests/file/symlink_link_linkinfo_is_link_basic1.phpt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Test symlink(), linkinfo(), link() and is_link() functions: basic functionality - link to files
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows') {
6+
require_once __DIR__ . '/windows_links/common.inc';
7+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
78
}
89
?>
910
--FILE--
@@ -58,7 +59,8 @@ foreach($files as $file) {
5859
// create soft link
5960
var_dump( symlink($file, $sym_linkname) );
6061
// checking information of link with linkinfo()
61-
var_dump( linkinfo($sym_linkname) );
62+
$linkinfo = linkinfo($sym_linkname);
63+
var_dump( is_int($linkinfo) && $linkinfo !== -1 );
6264
// checking if given file is soft link
6365
var_dump( is_link($sym_linkname) );
6466
// clear the cache
@@ -69,7 +71,8 @@ foreach($files as $file) {
6971
// creating hard link
7072
var_dump( link($file, $linkname) );
7173
// checking information of link with linkinfo()
72-
var_dump( linkinfo($linkname) );
74+
$linkinfo = linkinfo($sym_linkname);
75+
var_dump( is_int($linkinfo) && $linkinfo !== -1 );
7376
// checking if given link is soft link; expected: false
7477
var_dump( is_link($linkname) );
7578
// clear the cache
@@ -95,20 +98,20 @@ rmdir($dirname);
9598
-- Iteration 1 --
9699
-- Testing on soft links --
97100
bool(true)
98-
int(%d)
101+
bool(true)
99102
bool(true)
100103
-- Testing on hard links --
101104
bool(true)
102-
int(%d)
105+
bool(true)
103106
bool(false)
104107

105108
-- Iteration 2 --
106109
-- Testing on soft links --
107110
bool(true)
108-
int(%d)
111+
bool(true)
109112
bool(true)
110113
-- Testing on hard links --
111114
bool(true)
112-
int(%d)
115+
bool(true)
113116
bool(false)
114117
Done

ext/standard/tests/file/symlink_link_linkinfo_is_link_basic2.phpt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Test symlink(), linkinfo(), link() and is_link() functions: basic functionality - link to dirs
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows') {
6+
require_once __DIR__ . '/windows_links/common.inc';
7+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
78
}
89
?>
910
--FILE--
@@ -44,7 +45,8 @@ echo "\n-- Testing on soft links --\n";
4445
// creating soft link to $dirname
4546
var_dump( symlink("$file_path/$dirname", $sym_linkname) ); // this works, expected true
4647
// gets information about soft link created to directory; expected: true
47-
var_dump( linkinfo($sym_linkname) );
48+
$linkinfo = linkinfo($sym_linkname);
49+
var_dump( is_int($linkinfo) && $linkinfo !== -1 );
4850
// checks if link created is soft link; expected: true
4951
var_dump( is_link($sym_linkname) );
5052
// clear the cache
@@ -60,7 +62,11 @@ var_dump( is_link($linkname) ); // link doesn't exists as not created, expected
6062
clearstatcache();
6163

6264
// deleting the links
63-
unlink($sym_linkname);
65+
if (PHP_OS_FAMILY === 'Windows') {
66+
rmdir($sym_linkname);
67+
} else {
68+
unlink($sym_linkname);
69+
}
6470

6571
echo "Done\n";
6672
?>
@@ -76,7 +82,7 @@ rmdir($dirname);
7682

7783
-- Testing on soft links --
7884
bool(true)
79-
int(%d)
85+
bool(true)
8086
bool(true)
8187

8288
-- Testing on hard links --

ext/standard/tests/file/symlink_link_linkinfo_is_link_error1.phpt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
Test symlink(), linkinfo(), link() and is_link() functions : error conditions - symlink & linkinfo
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
7-
}
85
if (substr(PHP_OS, 0, 3) == 'SUN') {
96
die('skip Not valid for Sun Solaris');
107
}

ext/standard/tests/file/symlink_link_linkinfo_is_link_error2.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Test symlink(), linkinfo(), link() and is_link() functions : error conditions - link & is_link
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows' && PHP_ZTS) {
6+
die('xfail different handling of space as filename with ZTS/NTS on Windows');
77
}
88
?>
99
--FILE--

ext/standard/tests/file/symlink_link_linkinfo_is_link_variation1.phpt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link name stored in an array/object
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows') {
6+
require_once __DIR__ . '/windows_links/common.inc';
7+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
78
}
89
?>
910
--FILE--
@@ -47,7 +48,8 @@ echo "\n-- Working with soft links --\n";
4748
// creating soft link
4849
var_dump( symlink($filename, $obj->linkname) );
4950
// check if the link exists
50-
var_dump( linkinfo($obj->linkname) );
51+
$linkinfo = linkinfo($obj->linkname);
52+
var_dump( is_int($linkinfo) && $linkinfo !== -1 );
5153
// check if link is soft link
5254
var_dump( is_link($obj->linkname) );
5355
// delete the link created
@@ -60,7 +62,8 @@ echo "\n-- Working with hard links --\n";
6062
// creating hard link
6163
var_dump( link($filename, $obj->linkname) );
6264
// check if the link exists
63-
var_dump( linkinfo($obj->linkname) );
65+
$linkinfo = linkinfo($obj->linkname);
66+
var_dump( is_int($linkinfo) && $linkinfo !== -1 );
6467
// check if link is soft link; expected: false as the link is a hardlink
6568
var_dump( is_link($obj->linkname) );
6669
// delete the link created
@@ -77,7 +80,8 @@ echo "\n-- Working with soft links --\n";
7780
// creating soft link
7881
var_dump( symlink($filename, $link_arr[0]) );
7982
// check if the link exist
80-
var_dump( linkinfo($link_arr[0]) );
83+
$linkinfo = linkinfo($link_arr[0]);
84+
var_dump( is_int($linkinfo) && $linkinfo !== -1 );
8185
// check if link is soft link
8286
var_dump( is_link($link_arr[0]) );
8387
// delete the link created
@@ -90,7 +94,8 @@ echo "\n-- Working with hard links --\n";
9094
// creating hard link
9195
var_dump( link($filename, $link_arr[0]) );
9296
// check if the link exist
93-
var_dump( linkinfo($link_arr[0]) );
97+
$linkinfo = linkinfo($link_arr[0]);
98+
var_dump( is_int($linkinfo) && $linkinfo !== -1 );
9499
// check if link is soft link; expected: false as this is a hardlink
95100
var_dump( is_link($link_arr[0]) );
96101
// delete the links created
@@ -114,23 +119,23 @@ rmdir($dirname);
114119

115120
-- Working with soft links --
116121
bool(true)
117-
int(%d)
122+
bool(true)
118123
bool(true)
119124

120125
-- Working with hard links --
121126
bool(true)
122-
int(%d)
127+
bool(true)
123128
bool(false)
124129

125130
*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members of an array ***
126131

127132
-- Working with soft links --
128133
bool(true)
129-
int(%d)
134+
bool(true)
130135
bool(true)
131136

132137
-- Working with hard links --
133138
bool(true)
134-
int(%d)
139+
bool(true)
135140
bool(false)
136141
Done

ext/standard/tests/file/symlink_link_linkinfo_is_link_variation2.phpt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
--TEST--
22
Test symlink(), linkinfo(), link() and is_link() functions : usage variations - hardlink to non-existent file
3-
--SKIPIF--
4-
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
7-
}
8-
?>
93
--FILE--
104
<?php
115
/* Prototype: bool symlink ( string $target, string $link );

ext/standard/tests/file/symlink_link_linkinfo_is_link_variation3.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Test symlink(), linkinfo(), link() and is_link() functions : usage variations - access/update file through softlink
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows') {
6+
require_once __DIR__ . '/windows_links/common.inc';
7+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
78
}
89
?>
910
--FILE--

ext/standard/tests/file/symlink_link_linkinfo_is_link_variation4.phpt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
--TEST--
22
Test symlink(), linkinfo(), link() and is_link() functions : usage variations - access/update file through hard link
3-
--SKIPIF--
4-
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
7-
}
8-
?>
93
--FILE--
104
<?php
115
/* Prototype: bool symlink ( string $target, string $link );

ext/standard/tests/file/symlink_link_linkinfo_is_link_variation5.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Test symlink(), linkinfo(), link() and is_link() functions : usage variations - work on deleted link
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows') {
6+
require_once __DIR__ . '/windows_links/common.inc';
7+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
78
}
89
?>
910
--FILE--

ext/standard/tests/file/symlink_link_linkinfo_is_link_variation6.phpt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link & dir perms.
33
--SKIPIF--
44
<?php
5-
if ( substr(PHP_OS, 0, 3) == 'WIN' ) {
6-
die('skip no symlinks on Windows');
7-
}
85
require __DIR__ . '/../skipif_root.inc';
96
?>
107
--FILE--

ext/standard/tests/file/symlink_link_linkinfo_is_link_variation7.phpt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Test symlink(), linkinfo(), link() and is_link() functions : usage variations - try link to self
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows') {
6+
require_once __DIR__ . '/windows_links/common.inc';
7+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
78
}
89
?>
910
--FILE--
@@ -51,7 +52,11 @@ var_dump( symlink($dirname, $linkname) );
5152
// create another link to $dirname
5253
var_dump( symlink($linkname, $linkname) );
5354
// delete link
54-
unlink($linkname);
55+
if (PHP_OS_FAMILY === 'Windows') {
56+
rmdir($linkname);
57+
} else {
58+
unlink($linkname);
59+
}
5560

5661
echo "\n*** Create hard link to file and then to itself ***\n";
5762
// create hard link to $filename

ext/standard/tests/file/symlink_link_linkinfo_is_link_variation8.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Test symlink(), linkinfo(), link() and is_link() functions : usage variations - try link with same name in diff. dir
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows') {
6+
require_once __DIR__ . '/windows_links/common.inc';
7+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
78
}
89
?>
910
--FILE--
@@ -77,7 +78,7 @@ bool(true)
7778

7879
*** Create soft link in different directory with same filename ***
7980

80-
Warning: symlink(): File exists in %s on line %d
81+
Warning: symlink(): %rFile exists|Permission denied%r in %s on line %d
8182
bool(false)
8283
bool(true)
8384
Done

ext/standard/tests/file/symlink_link_linkinfo_is_link_variation9.phpt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link & lstat[dev] value
33
--SKIPIF--
44
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip no symlinks on Windows');
5+
if (PHP_OS_FAMILY === 'Windows') {
6+
require_once __DIR__ . '/windows_links/common.inc';
7+
skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
78
}
89
?>
910
--FILE--
@@ -45,8 +46,8 @@ var_dump( symlink($filename, $soft_link) );
4546
// confirming that linkinfo() = lstat['dev'] , this should always match
4647
$linkinfo = linkinfo($soft_link);
4748
$s1 = lstat($soft_link);
48-
echo "linkinfo() returns : $linkinfo\n";
49-
echo "lstat() returns lstat['dev'] as $s1[0]\n";
49+
echo "linkinfo() returns integer !== -1: ";
50+
var_dump(is_int($linkinfo) && $linkinfo !== -1);
5051
if( $s1[0] == $linkinfo )
5152
echo "\nlinkinfo() value matches lstat['dev']\n";
5253
else
@@ -60,8 +61,8 @@ var_dump( link($filename, $hard_link) );
6061
// confirming that linkinfo() = lstat['dev'] , this should always match
6162
$linkinfo = linkinfo($hard_link);
6263
$s1 = lstat($hard_link);
63-
echo "linkinfo() returns : $linkinfo\n";
64-
echo "lstat() returns lstat['dev'] as $s1[0]\n";
64+
echo "linkinfo() returns integer !== -1: ";
65+
var_dump(is_int($linkinfo) && $linkinfo !== -1);
6566
if( $s1[0] == $linkinfo )
6667
echo "\nlinkinfo() value matches lstat['dev']\n";
6768
else
@@ -77,15 +78,19 @@ var_dump( symlink($dirname, $soft_link) );
7778
// confirming that linkinfo() = lstat['dev'], this should always match
7879
$linkinfo = linkinfo($soft_link);
7980
$s1 = lstat($soft_link);
80-
echo "linkinfo() returns : $linkinfo\n";
81-
echo "lstat() returns lstat['dev'] as $s1[0]\n";
81+
echo "linkinfo() returns integer !== -1: ";
82+
var_dump(is_int($linkinfo) && $linkinfo !== -1);
8283
if( $s1[0] == $linkinfo )
8384
echo "\nlinkinfo() value matches lstat['dev']\n";
8485
else
8586
echo "\nWarning: linkinfo() value doesnt match lstat['dev']\n";
8687

8788
// delete link
88-
unlink($soft_link);
89+
if (PHP_OS_FAMILY === 'Windows') {
90+
rmdir($soft_link);
91+
} else {
92+
unlink($soft_link);
93+
}
8994

9095
echo "Done\n";
9196
?>
@@ -100,22 +105,19 @@ rmdir($dirname);
100105
--EXPECTF--
101106
*** Checking lstat() on soft link ***
102107
bool(true)
103-
linkinfo() returns : %d
104-
lstat() returns lstat['dev'] as %d
108+
linkinfo() returns integer !== -1: bool(true)
105109

106110
linkinfo() value matches lstat['dev']
107111

108112
*** Checking lstat() on hard link ***
109113
bool(true)
110-
linkinfo() returns : %d
111-
lstat() returns lstat['dev'] as %d
114+
linkinfo() returns integer !== -1: bool(true)
112115

113116
linkinfo() value matches lstat['dev']
114117

115118
*** Checking lstat() on a soft link to directory ***
116119
bool(true)
117-
linkinfo() returns : %d
118-
lstat() returns lstat['dev'] as %d
120+
linkinfo() returns integer !== -1: bool(true)
119121

120122
linkinfo() value matches lstat['dev']
121123
Done

0 commit comments

Comments
 (0)