protected function _copyDirectory($source, $target)
    {
        $result = false;

        if (!is_dir($target)) {
            $result = mkdir($target, 0755, true);
        }
        else
        {
            // Clear directory
            $iter = new \RecursiveDirectoryIterator($target);
            foreach (new \RecursiveIteratorIterator($iter, \RecursiveIteratorIterator::CHILD_FIRST) as $f)
            {
                if ($f->isDir())
                {
                    if (!in_array($f->getFilename(), array('.', '..'))) {
                        rmdir($f->getPathname());
                    }
                } else {
                    unlink($f->getPathname());
                }
            }
        }

        if (is_dir($target))
        {
            $result = true; // needed for empty directories
            $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
            foreach ($iterator as $f)
            {
                if ($f->isDir()) {
                    $path = $target.'/'.$iterator->getSubPathName();
                    if (!is_dir($path)) {
                        $result = mkdir($path);
                    }
                } else {
                    $result = copy($f, $target.'/'.$iterator->getSubPathName());
                }

                if ($result === false) {
                    break;
                }
            }
        }

        return $result;
    }