summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/unlink_variation10.phpt
blob: 3a56a73a5ae31006e6ec38fb0cffa2f37fec4ca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
--TEST--
Test unlink() function : variation: unlinking directories
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
    die('skip.. Not for Windows');
}
?>
--FILE--
<?php
/* Prototype  : bool unlink(string filename[, context context])
 * Description: Delete a file
 * Source code: ext/standard/file.c
 * Alias to functions:
 */

echo "*** Testing unlink() : variation ***\n";

$workDir = "unlinkVar10.tmp";
$tmpDir = "subDir.tmp";
$dirToLinkTo = $workDir.'/'."linkme.tmp";

mkdir($workDir);
$cwd = getcwd();
mkdir($dirToLinkTo);

$dirs = array(
             // relative
             $workDir.'/'.$tmpDir,
             './'.$workDir.'/'.$tmpDir,
             $workDir.'/../'.$workDir.'/'.$tmpDir,

             //absolute
             $cwd.'/'.$workDir.'/'.$tmpDir,
             $cwd.'/./'.$workDir.'/'.$tmpDir,
             $cwd.'/'.$workDir.'/../'.$workDir.'/'.$tmpDir,

             // multiple separators
             $workDir.'//'.$tmpDir,
             $cwd.'//'.$workDir.'//'.$tmpDir,

             );


foreach($dirs as $dirToUnlink) {
   test_link($workDir.'/'.$tmpDir, $dirToLinkTo, $dirToUnlink, true);  //soft link
   //cannot test hard links unless you are root.
}

echo "\n--- try to unlink a directory ---\n";
unlink($dirToLinkTo);
rmdir($dirToLinkTo);
rmdir($workDir);

function test_link($linkedDir, $toLinkTo, $tounlink, $softlink) {
   if ($softlink == true) {
   	  symlink($toLinkTo, $linkedDir);
   	  $msg = "soft link";
   }
   else {
   	  link($toLinkTo, $linkedDir);
   	  $msg = "hard link";
   }
   echo "-- unlinking $msg $tounlink --\n";
   $res = unlink($tounlink);
   if ($res === true) {
      if (is_link($tounlink) === false) {
      	echo "directory unlinked\n";
      }
      else {
        echo "FAILED: directory not unlinked\n";
      }
   }
   else {
      unlink($linkedDir);
   }
}


?>
--EXPECTF--
*** Testing unlink() : variation ***
-- unlinking soft link unlinkVar10.tmp/subDir.tmp --
directory unlinked
-- unlinking soft link ./unlinkVar10.tmp/subDir.tmp --
directory unlinked
-- unlinking soft link unlinkVar10.tmp/../unlinkVar10.tmp/subDir.tmp --
directory unlinked
-- unlinking soft link /%s/unlinkVar10.tmp/subDir.tmp --
directory unlinked
-- unlinking soft link /%s/./unlinkVar10.tmp/subDir.tmp --
directory unlinked
-- unlinking soft link /%s/unlinkVar10.tmp/../unlinkVar10.tmp/subDir.tmp --
directory unlinked
-- unlinking soft link unlinkVar10.tmp//subDir.tmp --
directory unlinked
-- unlinking soft link /%s//unlinkVar10.tmp//subDir.tmp --
directory unlinked

--- try to unlink a directory ---

Warning: unlink(unlinkVar10.tmp/linkme.tmp): %s in %s on line %d