/** * Deleting files and folders (action=4) * * @param array $cmds['data'] is the file/folder to delete * @return boolean Returns true upon success */ function func_delete($cmds) { if (!$this->isInit) { return FALSE; } // Checking path: $theFile = $cmds['data']; if (!$this->isPathValid($theFile)) { $this->writelog(4, 2, 101, 'Target "%s" had invalid path (".." and "//" is not allowed in path).', array($theFile)); return FALSE; } // Recycler moving or not? if ($this->useRecycler && ($recyclerPath = $this->findRecycler($theFile))) { // If a recycler is found, the deleted items is moved to the recycler and not just deleted. $newCmds = array(); $newCmds['data'] = $theFile; $newCmds['target'] = $recyclerPath; $newCmds['altName'] = 1; $this->func_move($newCmds); $this->writelog(4, 0, 4, 'Item "%s" moved to recycler at "%s"', array($theFile, $recyclerPath)); return TRUE; } elseif ($this->useRecycler != 2) { // if $this->useRecycler==2 then we cannot delete for real!! if (@is_file($theFile)) { // If we are deleting a file... if ($this->actionPerms['deleteFile']) { if ($this->checkPathAgainstMounts($theFile)) { if (@unlink($theFile)) { $this->writelog(4, 0, 1, 'File "%s" deleted', array($theFile)); return TRUE; } else { $this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', array($theFile)); } } else { $this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', array($theFile)); } } else { $this->writelog(4, 1, 112, 'You are not allowed to delete files', ''); } // FINISHED deleting file } elseif (@is_dir($theFile)) { // if we're deleting a folder if ($this->actionPerms['deleteFolder']) { $theFile = $this->is_directory($theFile); if ($theFile) { if ($this->checkPathAgainstMounts($theFile)) { // I choose not to append '/' to $theFile here as this will prevent us from deleting mounts!! (which makes sense to me...) if ($this->actionPerms['deleteFolderRecursively']) { if (t3lib_div::rmdir($theFile, true)) { $this->writelog(4, 0, 2, 'Directory "%s" deleted recursively!', array($theFile)); return TRUE; } else { $this->writelog(4, 2, 119, 'Directory "%s" WAS NOT deleted recursively! Write-permission problem?', array($theFile)); } } else { if (@rmdir($theFile)) { $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($theFile)); return TRUE; } else { $this->writelog(4, 1, 120, 'Could not delete directory! Write-permission problem? Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($theFile)); } } } else { $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($theFile)); } } else { $this->writelog(4, 2, 122, 'Target seemed not to be a directory! (Shouldn\'t happen here!)', ''); } } else { $this->writelog(4, 1, 123, 'You are not allowed to delete directories', ''); } // FINISHED copying directory } else { $this->writelog(4, 2, 130, 'The item was not a file or directory! "%s"', array($theFile)); } } else { $this->writelog(4, 1, 131, 'No recycler found!', ''); } }
/** * Deletes the dummy folder specified in the first parameter $folderName. * The folder must be empty (no files or subfolders). * * @param string $folderName * the path to the folder to delete relative to * $this->uploadFolderPath, must not be empty * * @return void * * @throws InvalidArgumentException * @throws t3lib_exception */ public function deleteDummyFolder($folderName) { $absolutePathToFolder = $this->uploadFolderPath . $folderName; if (!is_dir($absolutePathToFolder)) { throw new InvalidArgumentException('The folder "' . $absolutePathToFolder . '" which you are trying to delete does not exist.', 1334439343); } if (!isset($this->dummyFolders[$folderName])) { throw new InvalidArgumentException('The folder "' . $absolutePathToFolder . '" which you are trying to delete was not created by this instance of ' . 'the testing framework.', 1334439387); } if (!t3lib_div::rmdir($absolutePathToFolder)) { throw new t3lib_exception('The folder "' . $absolutePathToFolder . '" could not be deleted.', 1334439393); } unset($this->dummyFolders[$folderName]); }
/** * @author Robert Lemke <*****@*****.**> * @author Ingo Renner <*****@*****.**> */ public function tearDown() { if (is_object($this->backend)) { $directory = $this->backend->getCacheDirectory(); if (is_dir($directory)) { t3lib_div::rmdir($directory, TRUE); } } foreach ($this->backupGlobalVariables as $key => $data) { $GLOBALS[$key] = $data; } }
/** * Clears page cache. Takes into account file cache. * * @return void */ function internal_clearPageCache() { if (TYPO3_UseCachingFramework) { if (t3lib_extMgm::isLoaded('cms')) { $GLOBALS['typo3CacheManager']->getCache('cache_pages')->flush(); } } else { if (t3lib_extMgm::isLoaded('cms')) { if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageCacheToExternalFiles']) { $cacheDir = PATH_site . 'typo3temp/cache_pages'; $retVal = t3lib_div::rmdir($cacheDir, TRUE); if (!$retVal) { t3lib_div::sysLog('Could not remove page cache files in "' . $cacheDir . '"', 'Core/t3lib_tcemain', 2); } } $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_pages'); } } }
/** * Clear the cache. * * @param &array $params The parameters. * @return boolean TRUE if the cache has successfully been cleared, false otherwise. * @author Romain Ruetschi <*****@*****.**> */ public function clearCache(&$params) { // We only clear the cache if "Clear all cache" has been selected. if ($params['cacheCmd'] !== 'all') { return false; } // Build the cache directories index. $this->buildCacheDirectoriesIndex(); // Holds the state of the process. $status = TRUE; // For each register cache directory. foreach ($this->cacheDirectories as $cacheDirectory) { // Recursively remove the directory and update success status. $status = $status && t3lib_div::rmdir(t3lib_div::getFileAbsFileName($cacheDirectory), TRUE); } // Return the status. return $status; }
/** * Removes all cache entries of this cache. * * @return void * @author Robert Lemke <*****@*****.**> * @author Christian Kuhn <*****@*****.**> * @api */ public function flush() { t3lib_div::rmdir($this->root . $this->cacheDirectory, TRUE); }
/** * Wrapper function for rmdir, allowing recursive deletion of folders and files * * @param string Absolute path to folder, see PHP rmdir() function. Removes trailing slash internally. * @param boolean Allow deletion of non-empty directories * @return boolean true if @rmdir went well! */ public static function rmdir($path, $removeNonEmpty = false) { $OK = false; $path = preg_replace('|/$|', '', $path); // Remove trailing slash if (file_exists($path)) { $OK = true; if (is_dir($path)) { if ($removeNonEmpty == true && ($handle = opendir($path))) { while ($OK && false !== ($file = readdir($handle))) { if ($file == '.' || $file == '..') { continue; } $OK = t3lib_div::rmdir($path . '/' . $file, $removeNonEmpty); } closedir($handle); } if ($OK) { $OK = rmdir($path); } } else { // If $dirname is a file, simply remove it $OK = unlink($path); } clearstatcache(); } return $OK; }
/** * Checks if t3lib_div::mkdir() correctly creates a directory with trailing slash * This test assumes directory 'PATH_site'/typo3temp exists * * @test * @see t3lib_div::mkdir() */ public function checkMkdirCorrectlyCreatesDirectoryWithTrailingSlash() { $directory = PATH_site . 'typo3temp/' . uniqid('test_'); $mkdirResult = t3lib_div::mkdir($directory); $directoryCreated = is_dir($directory); t3lib_div::rmdir($directory); $this->assertTrue($mkdirResult); $this->assertTrue($directoryCreated); }
/** * Deletes a "foreign" folder which was created for test purposes. * * @return void */ private function deleteForeignFolder() { if ($this->foreignFolderToDelete == '') { return; } t3lib_div::rmdir($this->foreignFolderToDelete); $this->foreignFolderToDelete = ''; }
/** * Install translations for all selected languages for an extension * * @param string $extKey The extension key to install the translations for * @param string $lang Language code of translation to fetch * @param string $mirrorURL Mirror URL to fetch data from * @return mixed true on success, error string on fauilure */ function updateTranslation($extKey, $lang, $mirrorURL) { $l10n = $this->parentObject->terConnection->fetchTranslation($extKey, $lang, $mirrorURL); if (is_array($l10n)) { $file = PATH_site . 'typo3temp/' . $extKey . '-l10n-' . $lang . '.zip'; $path = 'l10n/' . $lang . '/'; if (!is_dir(PATH_typo3conf . $path)) { t3lib_div::mkdir_deep(PATH_typo3conf, $path); } t3lib_div::writeFile($file, $l10n[0]); // this prevent first update having errors t3lib_div::rmdir(PATH_typo3conf . $path . $extKey, TRUE); if (tx_em_Tools::unzip($file, PATH_typo3conf . $path)) { return TRUE; } else { return $GLOBALS['LANG']->getLL('translation_unpacking_failed'); } } else { return $l10n; } }
/** * (non-PHPdoc) * @see tx_mklib_tests_DBTestCaseSkeleton::tearDown() */ public function tearDown() { t3lib_div::rmdir($this->sTempFolder, true); }
/** * Clean up after the tests * * @return void * @author Karsten Dambekalns <*****@*****.**> */ public function tearDown() { if ($this->fixtureDB) { t3lib_div::rmdir($this->fixtureFolder, TRUE); } foreach ($this->backupGlobalVariables as $key => $data) { $GLOBALS[$key] = $data; } }
public function testCleanupFilesRecursiveWithZipAndXml() { //@TODO: lifetime testen // testverzeichnis anlegen $testfolder = t3lib_extMgm::extPath('mklib', 'tests/fixtures/toremove'); self::createTestfiles($testfolder); // das aufräumen! $count = tx_mklib_util_File::cleanupFiles($testfolder . '/', array('lifetime' => -10800, 'recursive' => '1', 'filetypes' => 'zip, xml', 'skiptypo3tempcheck' => '1')); $this->assertEquals(4, $count, 'wrong deleted count. testfolder: ' . $testfolder); // weider löschen t3lib_div::rmdir($testfolder, true); }