1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link & dir perms.
3--SKIPIF--
4<?php
5require __DIR__ . '/../skipif_root.inc';
6?>
7--FILE--
8<?php
9/* Variation 6 : Change permission of directory and try creating links inside that directory */
10$file_path = __DIR__;
11
12echo "*** Creating links in a directory without permission to allow the operation ***\n";
13// temp file used
14$dirname = "$file_path/symlink_link_linkinfo_is_link_variation6";
15mkdir($dirname);
16$filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp";
17
18// remove all permissions from dir
19var_dump( chmod($dirname, 0000) );
20
21echo "\n-- Working with soft links --\n";
22$linkname = "$dirname/non_existent_link_variation5.tmp";
23
24// expected: false
25var_dump( symlink($filename, $linkname) ); // this link won't get created
26var_dump( linkinfo($linkname) );
27var_dump( is_link($linkname) );
28// clear the cache
29clearstatcache();
30
31echo "\n-- Working with hard links --\n";
32// expected: false
33var_dump( link($filename, $linkname) );
34var_dump( linkinfo($linkname) );
35var_dump( is_link($linkname) );
36// clear the cache
37clearstatcache();
38
39chmod($dirname, 0777);  // to enable dir deletion
40echo "Done\n";
41?>
42--CLEAN--
43<?php
44$file_path = __DIR__;
45$dirname = "$file_path/symlink_link_linkinfo_is_link_variation6";
46$filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp";
47if(file_exists($filename)) {
48unlink($filename);
49}
50if(file_exists($dirname)) {
51rmdir($dirname);
52}
53?>
54--EXPECTF--
55*** Creating links in a directory without permission to allow the operation ***
56bool(true)
57
58-- Working with soft links --
59
60Warning: symlink(): Permission denied in %s on line %d
61bool(false)
62
63Warning: linkinfo(): Permission denied in %s on line %d
64int(-1)
65bool(false)
66
67-- Working with hard links --
68
69Warning: link(): Permission denied in %s on line %d
70bool(false)
71
72Warning: linkinfo(): Permission denied in %s on line %d
73int(-1)
74bool(false)
75Done
76