1--TEST--
2Test unlink() function : variation: unlinking directories
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if (substr(PHP_OS, 0, 3) == 'WIN') {
8    die('skip.. Not for Windows');
9}
10?>
11--FILE--
12<?php
13echo "*** Testing unlink() : variation ***\n";
14
15$workDir = "unlinkVar10.tmp";
16$tmpDir = "subDir.tmp";
17$dirToLinkTo = $workDir.'/'."linkme.tmp";
18
19mkdir($workDir);
20$cwd = getcwd();
21mkdir($dirToLinkTo);
22
23$dirs = array(
24             // relative
25             $workDir.'/'.$tmpDir,
26             './'.$workDir.'/'.$tmpDir,
27             $workDir.'/../'.$workDir.'/'.$tmpDir,
28
29             //absolute
30             $cwd.'/'.$workDir.'/'.$tmpDir,
31             $cwd.'/./'.$workDir.'/'.$tmpDir,
32             $cwd.'/'.$workDir.'/../'.$workDir.'/'.$tmpDir,
33
34             // multiple separators
35             $workDir.'//'.$tmpDir,
36             $cwd.'//'.$workDir.'//'.$tmpDir,
37
38             );
39
40
41foreach($dirs as $dirToUnlink) {
42   test_link($workDir.'/'.$tmpDir, $dirToLinkTo, $dirToUnlink, true);  //soft link
43   //cannot test hard links unless you are root.
44}
45
46echo "\n--- try to unlink a directory ---\n";
47unlink($dirToLinkTo);
48rmdir($dirToLinkTo);
49rmdir($workDir);
50
51function test_link($linkedDir, $toLinkTo, $tounlink, $softlink) {
52   if ($softlink == true) {
53      symlink($toLinkTo, $linkedDir);
54      $msg = "soft link";
55   }
56   else {
57      link($toLinkTo, $linkedDir);
58      $msg = "hard link";
59   }
60   echo "-- unlinking $msg $tounlink --\n";
61   $res = unlink($tounlink);
62   if ($res === true) {
63      if (is_link($tounlink) === false) {
64        echo "directory unlinked\n";
65      }
66      else {
67        echo "FAILED: directory not unlinked\n";
68      }
69   }
70   else {
71      unlink($linkedDir);
72   }
73}
74
75
76?>
77--EXPECTF--
78*** Testing unlink() : variation ***
79-- unlinking soft link unlinkVar10.tmp/subDir.tmp --
80directory unlinked
81-- unlinking soft link ./unlinkVar10.tmp/subDir.tmp --
82directory unlinked
83-- unlinking soft link unlinkVar10.tmp/../unlinkVar10.tmp/subDir.tmp --
84directory unlinked
85-- unlinking soft link /%s/unlinkVar10.tmp/subDir.tmp --
86directory unlinked
87-- unlinking soft link /%s/./unlinkVar10.tmp/subDir.tmp --
88directory unlinked
89-- unlinking soft link /%s/unlinkVar10.tmp/../unlinkVar10.tmp/subDir.tmp --
90directory unlinked
91-- unlinking soft link unlinkVar10.tmp//subDir.tmp --
92directory unlinked
93-- unlinking soft link /%s//unlinkVar10.tmp//subDir.tmp --
94directory unlinked
95
96--- try to unlink a directory ---
97
98Warning: unlink(unlinkVar10.tmp/linkme.tmp): %s in %s on line %d
99