Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
--TEST-- Test unlink() function : variation: unlinking directories --CREDITS-- Dave Kelsey..
Decoded Output download
--TEST--
Test unlink() function : variation: unlinking directories
--CREDITS--
Dave Kelsey <[email protected]>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip.. Not for Windows');
}
?>
--FILE--
<?php
echo "*** Testing unlink() : variation ***
";
$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 "
--- try to unlink a directory ---
";
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 --
";
$res = unlink($tounlink);
if ($res === true) {
if (is_link($tounlink) === false) {
echo "directory unlinked
";
}
else {
echo "FAILED: directory not unlinked
";
}
}
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
Did this file decode correctly?
Original Code
--TEST--
Test unlink() function : variation: unlinking directories
--CREDITS--
Dave Kelsey <[email protected]>
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip.. Not for Windows');
}
?>
--FILE--
<?php
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
Function Calls
None |
Stats
MD5 | 7a594177d82053f804bd49e43e99db88 |
Eval Count | 0 |
Decode Time | 104 ms |