1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - try link with same name in diff. dir
3--SKIPIF--
4<?php
5if (PHP_OS_FAMILY === 'Windows') {
6    require_once __DIR__ . '/windows_links/common.inc';
7    skipIfSeCreateSymbolicLinkPrivilegeIsDisabled(__FILE__);
8}
9?>
10--FILE--
11<?php
12/* Variation 8 : Create soft/hard link to different directory */
13
14/* creating link to a file in different dir with the same name as the file */
15echo "\n*** Create hard link in different directory with same filename ***\n";
16// temp file used
17$file_path = __DIR__;
18$filename = "$file_path/symlink_link_linkinfo_is_link_variation8.tmp";
19// temp link name used
20$dirname = "$file_path/symlink_link_linkinfo_is_link1_variation8";
21mkdir($dirname);
22$linkname = "symlink_link_linkinfo_is_link_variation8.tmp";
23// create temp file
24$fp = fopen($filename, "w");
25fclose($fp);
26
27var_dump( link($filename, $dirname."/") ); // this fails indicating file exists
28// ok, creates "$file_path/symlink_link_linkinfo_is_link1_variation8/symlink_link_linkinfo_is_link_variation8.tmp" link
29var_dump( link($filename, $dirname."/".$linkname) );  // this works fine
30// delete link
31unlink($dirname."/".$linkname);
32// delete temp file
33unlink($filename);
34// delete temp dir
35rmdir($dirname);
36
37echo "\n*** Create soft link in different directory with same filename ***\n";
38$filename = "$file_path/symlink_link_linkinfo_is_link_variation8.tmp";
39// temp link name used
40$dirname = "$file_path/symlink_link_linkinfo_is_link1_variation8";
41mkdir($dirname);
42$linkname = "symlink_link_linkinfo_is_link_variation8.tmp";
43// create temp file
44$fp = fopen($filename, "w");
45fclose($fp);
46
47var_dump( symlink($filename, $dirname."/") ); // this fails indicating file exists
48// ok, creates "$file_path/symlink_link_linkinfo_is_link1_variation8/symlink_link_linkinfo_is_link_variation8.tmp" link
49var_dump( symlink($filename, $dirname."/".$linkname) );  // this works fine
50// delete link
51unlink($dirname."/".$linkname);
52// delete temp file
53unlink($filename);
54// delete temp dir
55rmdir($dirname);
56
57echo "Done\n";
58?>
59--EXPECTF--
60*** Create hard link in different directory with same filename ***
61
62Warning: link(): File exists in %s on line %d
63bool(false)
64bool(true)
65
66*** Create soft link in different directory with same filename ***
67
68Warning: symlink(): %rFile exists|Permission denied%r in %s on line %d
69bool(false)
70bool(true)
71Done
72