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 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 19echo "*** Testing unlink() : variation ***\n"; 20 21$workDir = "unlinkVar8.tmp"; 22$tmpDir = "subDir.tmp"; 23$dirToLinkTo = $workDir.'/'."linkme.tmp"; 24 25mkdir($workDir); 26$cwd = getcwd(); 27mkdir($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 47foreach($dirs as $dirToUnlink) { 48 test_link($workDir.'/'.$tmpDir, $dirToLinkTo, $dirToUnlink, true); //soft link 49 //cannot test hard links unless you are root. 50} 51 52echo "\n--- try to unlink a directory ---\n"; 53unlink($dirToLinkTo); 54rmdir($dirToLinkTo); 55rmdir($workDir); 56 57function 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 -- 87directory unlinked 88-- unlinking soft link ./unlinkVar8.tmp/subDir.tmp -- 89directory unlinked 90-- unlinking soft link unlinkVar8.tmp/../unlinkVar8.tmp/subDir.tmp -- 91directory unlinked 92-- unlinking soft link /%s/unlinkVar8.tmp/subDir.tmp -- 93directory unlinked 94-- unlinking soft link /%s/./unlinkVar8.tmp/subDir.tmp -- 95directory unlinked 96-- unlinking soft link /%s/unlinkVar8.tmp/../unlinkVar8.tmp/subDir.tmp -- 97directory unlinked 98-- unlinking soft link unlinkVar8.tmp//subDir.tmp -- 99directory unlinked 100-- unlinking soft link /%s//unlinkVar8.tmp//subDir.tmp -- 101directory unlinked 102 103--- try to unlink a directory --- 104 105Warning: unlink(unlinkVar8.tmp/linkme.tmp): %s in %s on line %d 106===DONE===