Exemple #1
0
 public function clean(\Nano\TestUtils\TestCase $test, $dir, $fullPath = false)
 {
     if (false === $fullPath) {
         $dir = $this->get($test, $dir);
     }
     if (!file_exists($dir)) {
         mkDir($dir, 0755, true);
         return true;
     }
     $i = new \DirectoryIterator($dir);
     $result = true;
     foreach ($i as $file) {
         /** @var \DirectoryIterator $file */
         if ($file->isDot()) {
             continue;
         }
         if (self::EMPTY_FILE == $file->getBaseName()) {
             $result = false;
             continue;
         }
         if ($file->isDir()) {
             if ($this->clean($test, $file->getPathName(), true)) {
                 rmDir($file->getPathName());
             }
             continue;
         }
         unLink($file->getPathName());
     }
     unset($i, $file);
     return $result;
 }
Exemple #2
0
 protected function tearDown()
 {
     $this->files->clean($this, '/for-clear');
     $dir = $this->files->get($this, '/not-exists');
     if (is_dir($dir)) {
         rmDir($dir);
     }
 }
Exemple #3
0
 private function _clear($dir)
 {
     if (!file_exists($dir)) {
         return;
     }
     /** @var \DirectoryIterator $file */
     foreach (new \DirectoryIterator($dir) as $file) {
         if ($file->isFile()) {
             unlink($file->getRealPath());
         } else {
             if (!$file->isDot()) {
                 $this->_clear($file->getRealPath());
             }
         }
     }
     rmDir($dir);
 }
Exemple #4
0
 public function clean(PHPUnit_Framework_TestCase $test, $dir, $fullPath = false)
 {
     if (false === $fullPath) {
         $dir = $this->get($test, $dir);
     }
     $i = new DirectoryIterator($dir);
     foreach ($i as $file) {
         if ($file->isDot()) {
             continue;
         }
         if ($file->isDir()) {
             $this->clean($test, $file->getPathName(), true);
             rmDir($file->getPathName());
             continue;
         }
         unlink($file->getPathName());
     }
     unset($i, $file);
 }
Exemple #5
0
 /**
  * Deletes a directory and all files in it.
  *
  * @param    string  directory
  * @return   integer number of removed files
  * @throws   Cache_Error
  */
 function deleteDir($dir)
 {
     if (!($dh = opendir($dir))) {
         return new Cache_Error("Can't remove directory '{$dir}'. Check permissions and path.", __FILE__, __LINE__);
     }
     $num_removed = 0;
     while (false !== ($file = readdir($dh))) {
         if ('.' == $file || '..' == $file) {
             continue;
         }
         $file = $dir . $file;
         if (is_dir($file)) {
             $file .= '/';
             $num = $this->deleteDir($file . '/');
             if (is_int($num)) {
                 $num_removed += $num;
             }
         } else {
             if (unlink($file)) {
                 $num_removed++;
             }
         }
     }
     // according to php-manual the following is needed for windows installations.
     closedir($dh);
     unset($dh);
     if ($dir != $this->cache_dir) {
         //delete the sub-dir entries  itself also, but not the cache-dir.
         rmDir($dir);
         $num_removed++;
     }
     return $num_removed;
 }
 protected function _cleanupCopyDir($sSourceDir, $sTargetDir, $sSourceFilePath, $sTargetFilePath)
 {
     //try to remove dir and delete files
     if (unlink($sTargetFilePath)) {
         //$dirTargetHandle = opendir($sTargetDir);
         //closedir($dirTargetHandle);
         if (!rmDir($sTargetDir)) {
             $this->fail("could not remove {$sTargetDir} ");
         }
     } else {
         $this->fail("could not delete {$sTargetFilePath} ");
     }
     if (unlink($sSourceFilePath)) {
         //$dirSourceHandle = opendir($sSourceDir);
         //closedir($dirSourceHandle);
         if (!rmDir($sSourceDir)) {
             $this->fail("after remove not remove {$sSourceDir} ");
         }
     } else {
         $this->fail("could not delete {$sSourceFilePath} ");
     }
 }
Exemple #7
0
 /**
  * Removes all generated assets
  *
  * @return void
  * @param array $ignore
  * @param boolean $verbose
  */
 public function clearCache(array $ignore = array(), $verbose = false, $path = null)
 {
     if (!in_array('.svn', $ignore)) {
         $ignore[] = '.svn';
     }
     if (null === $path) {
         $path = $this->getBasePath();
     }
     $i = new DirectoryIterator($path);
     foreach ($i as $item) {
         if ($item->isDot()) {
             continue;
         }
         if (in_array($item->getBaseName(), $ignore)) {
             continue;
         }
         if ($item->isDir()) {
             $this->clearCache(array(), $verbose, $item->getPathName());
             $result = @rmDir($item->getPathName());
         } else {
             $result = @unlink($item->getPathName());
         }
         if (true === $verbose) {
             echo $item->getPathName();
             if (false === $result) {
                 echo ' ERROR';
             }
             echo PHP_EOL;
         }
     }
 }