/** * Attempts to remove the file indicated by the $sFilename path from the * filesystem. If the $filename indicates non-empty directory the function * will remove it along with all its content. * * @param string $sFilename * @return boolean True if the operation is successful, PEAR_Error if there * was a failure. */ function Util_File_remove($sFilename) { if (file_exists($sFilename)) { if (is_dir($sFilename)) { $directory = opendir($sFilename); if (false === $directory) { $error = new PEAR_Error("Can't open the directory: '{$sFilename}'."); return $error; } while (($sChild = readdir($directory)) !== false) { if ($sChild == '.' or $sChild == '..') { continue; } $result = Util_File_remove($sFilename . '/' . $sChild); if (PEAR::isError($result)) { return $result; } } closedir($directory); $result = rmdir($sFilename); if ($result === false) { $error = new PEAR_Error("Can't delete the directory: '{$sFilename}'."); return $error; } return true; } else { return Util_File_returnPearErrorIfFalse(unlink($sFilename), "Can't remove the file: '{$sFilename}'."); } } }
function tearDown() { // Resume normal service with regards to the configuration file writer... unset($GLOBALS['override_TEST_ENVIRONMENT_RUNNING']); if (file_exists(MAX_PATH . '/var/' . OX_getHostName() . '.conf.php')) { @unlink(MAX_PATH . '/var/' . OX_getHostName() . '.conf.php'); } $_SERVER['HTTP_HOST'] = $this->host; // Clean up Util_File_remove(MAX_PATH . '/var/plugins/config/'); }
function testUtil_File_remove() { $testDirectoryPath = MAX_PATH . '/var/tests'; mkdir($testDirectoryPath); mkdir($testDirectoryPath . '/subdir1'); mkdir($testDirectoryPath . '/subdir2'); touch($testDirectoryPath . '/normalfile.txt'); touch($testDirectoryPath . '/.hiddenfile.txt'); touch($testDirectoryPath . '/subdir1/normalfile.txt'); touch($testDirectoryPath . '/subdir1/.hiddenfile.txt'); $this->assertTrue(Util_File_remove($testDirectoryPath)); $this->assertFalse(file_exists($testDirectoryPath)); }
function testCreateGeoTargetingConfiguration() { if (file_exists(GEOCONFIG_PATH)) { rename(GEOCONFIG_PATH, TMP_GEOCONFIG_PATH); } $upgradeConfig = new OA_Upgrade_Config(); $host = OX_getHostName(); $migration = new Migration_108(); $migration->init($this->oDbh, MAX_PATH . '/var/DB_Upgrade.test.log'); $this->checkNoGeoTargeting($migration, $host); $this->checkGeoIp($migration, $host); $this->checkModGeoIP($migration, $host); Util_File_remove(GEOCONFIG_PATH); if (file_exists(TMP_GEOCONFIG_PATH)) { rename(TMP_GEOCONFIG_PATH, GEOCONFIG_PATH); } }