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