예제 #1
0
파일: FinderTest.php 프로젝트: insulin/cli
    public static function setupBeforeClass()
    {
        static::$root = sys_get_temp_dir() . '/insulin';
        static::$files = array(static::$root . '/modules/', static::$root . '/sugar/', static::$root . '/sugar/custom/', static::$root . '/sugar/include/', static::$root . '/sugar/include/entryPoint.php', static::$root . '/sugar/include/MVC/', static::$root . '/sugar/include/MVC/SugarApplication.php', static::$root . '/sugar/config.php', static::$root . '/sugar/sugar_version.php');
        static::$links = array(static::$root . '/modules' => static::$root . '/sugar/modules', static::$root . '/sugar/custom' => static::$root . '/custom');
        if (is_dir(static::$root)) {
            static::tearDownAfterClass();
        } else {
            mkdir(static::$root);
        }
        foreach (static::$files as $file) {
            if ('/' === substr($file, -1) && !is_dir($file)) {
                mkdir($file);
            } else {
                touch($file);
            }
        }
        foreach (static::$links as $target => $link) {
            symlink($target, $link);
        }
        file_put_contents(static::$root . '/sugar/sugar_version.php', '<?php
$sugar_version      = \'6.5.3\';
$sugar_db_version   = \'6.5.3\';
$sugar_flavor       = \'ENT\';
$sugar_build        = \'123\';
$sugar_timestamp    = \'2008-08-01 12:00am\';
');
    }
예제 #2
0
 /**
  * Recursive copy function
  * @param str src source path
  * @param str dst source path
  * @return bool
  */
 public static function cp_r($src, $dst)
 {
     if (is_link($src)) {
         $l = readlink($src);
         if (!symlink($l, $dst)) {
             return false;
         }
     } elseif (is_dir($src)) {
         if (!mkdir($dst)) {
             return false;
         }
         $objects = scandir($src);
         if ($objects === false) {
             return false;
         }
         foreach ($objects as $file) {
             if ($file == "." || $file == "..") {
                 continue;
             }
             if (!self::cp_r($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file)) {
                 return false;
             }
         }
     } else {
         if (!copy($src, $dst)) {
             return false;
         }
     }
     return true;
 }
 public function up()
 {
     $old = umask(0);
     mkdir(Config::get('upload_dir'), 0777);
     umask($old);
     symlink(Config::get('upload_dir'), Config::get('public_dir') . '/upload');
 }
예제 #4
0
 /**
  * Process document and write the result in the document cache.
  *
  * When the original document is required, create either a symbolic link with the
  * original document in the cache dir, or copy it in the cache dir if it's not already done.
  *
  * This method updates the cache_file_path and file_url attributes of the event
  *
  * @param DocumentEvent $event Event
  *
  * @throws \Thelia\Exception\DocumentException
  * @throws \InvalidArgumentException           , DocumentException
  */
 public function processDocument(DocumentEvent $event)
 {
     $subdir = $event->getCacheSubdirectory();
     $sourceFile = $event->getSourceFilepath();
     if (null == $subdir || null == $sourceFile) {
         throw new \InvalidArgumentException("Cache sub-directory and source file path cannot be null");
     }
     $originalDocumentPathInCache = $this->getCacheFilePath($subdir, $sourceFile, true);
     if (!file_exists($originalDocumentPathInCache)) {
         if (!file_exists($sourceFile)) {
             throw new DocumentException(sprintf("Source document file %s does not exists.", $sourceFile));
         }
         $mode = ConfigQuery::read('original_document_delivery_mode', 'symlink');
         if ($mode == 'symlink') {
             if (false == symlink($sourceFile, $originalDocumentPathInCache)) {
                 throw new DocumentException(sprintf("Failed to create symbolic link for %s in %s document cache directory", basename($sourceFile), $subdir));
             }
         } else {
             // mode = 'copy'
             if (false == @copy($sourceFile, $originalDocumentPathInCache)) {
                 throw new DocumentException(sprintf("Failed to copy %s in %s document cache directory", basename($sourceFile), $subdir));
             }
         }
     }
     // Compute the document URL
     $documentUrl = $this->getCacheFileURL($subdir, basename($originalDocumentPathInCache));
     // Update the event with file path and file URL
     $event->setDocumentPath($documentUrl);
     $event->setDocumentUrl(URL::getInstance()->absoluteUrl($documentUrl, null, URL::PATH_TO_FILE));
 }
예제 #5
0
 protected function makeSymlink($target, $link)
 {
     if (!@symlink($target, $link)) {
         $error = error_get_last();
         throw new ErrorException(sprintf("%s: %s -> %s\n", $error['message'], $link, $target));
     }
 }
 public function generatePhpbbLink($varValue, DataContainer $dc)
 {
     if (is_link($dc->activeRecord->phpbb_alias) && readlink($dc->activeRecord->phpbb_alias) == $varValue) {
         Message::addInfo("Path to forum already set");
         return $varValue;
     }
     if (is_link($dc->activeRecord->phpbb_alias) !== false && readlink($dc->activeRecord->phpbb_alias) != $varValue) {
         Message::addInfo("Removing old link");
         unlink($dc->activeRecord->phpbb_alias);
     }
     Message::addInfo("Trying to set Forum Symlink");
     if (file_exists($varValue . "/viewtopic.php")) {
         Message::addInfo("Forum found. Setting Link");
         $result = symlink($varValue, $dc->activeRecord->phpbb_alias);
         if ($result === true) {
             Message::addInfo("Link Set");
         }
         if (!is_link($dc->activeRecord->phpbb_alias . '/ext/ctsmedia') || readlink($dc->activeRecord->phpbb_alias . '/ext/ctsmedia') != "../../contao/vendor/ctsmedia/contao-phpbb-bridge-bundle/src/Resources/phpBB/ctsmedia") {
             Message::addInfo("Setting Vendor Link");
             symlink(TL_ROOT . "/vendor/ctsmedia/contao-phpbb-bridge-bundle/src/Resources/phpBB/ctsmedia", $dc->activeRecord->phpbb_alias . '/ext/ctsmedia');
         }
         Message::addInfo("Please activate the contao extension in the phpbb backend");
     } else {
         //Message::addError("Forum could not be found: ".$varValue . "/viewtopic.php");
         throw new Exception("Forum could not be found: " . $varValue . "/viewtopic.php");
     }
     return $varValue;
 }
예제 #7
0
파일: Assets.php 프로젝트: miaoxing/plugin
 /**
  * 发布素材到开放的目录
  */
 public function publishAction()
 {
     $cli = $this->cli;
     $plugins = $this->plugin->getAll();
     foreach ($plugins as $plugin) {
         $path = $plugin->getBasePath();
         // TODO V2 只处理vendor下的插件,直到迁移完毕
         if (strpos($path, 'vendor/') !== 0) {
             continue;
         }
         $source = $path . '/public';
         if (!is_dir($source)) {
             continue;
         }
         $id = $plugin->getId();
         $target = 'plugins/' . $id;
         if (is_dir($target)) {
             $this->writeln(sprintf('Remove %s', $cli->success($target)));
             $this->remove($target);
         }
         $source = '../' . $source;
         $this->writeln(sprintf('Symlink %s to %s', $cli->success($source), $cli->success($target)));
         symlink($source, $target);
     }
 }
 function main($source, $dest, $nested = 1)
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // notify user
     $this->notify($source, $dest, $nested);
     // Simple copy for a file
     if (is_file($source)) {
         return copy($source, $dest);
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if (substr($entry, 0, 1) == '.' || $entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         $this->main("{$source}/{$entry}", "{$dest}/{$entry}", $nested + 1);
     }
     // Clean up
     $dir->close();
     return true;
 }
예제 #9
0
파일: AssetsTask.php 프로젝트: arius86/core
 /**
  * Copies assets recursively
  *
  * @param $source
  * @param $dest
  * @param int $permissions
  * @return bool
  * @internal
  */
 private function copyRecursive($source, $dest, $permissions = 0755)
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Simple copy for a file
     if (is_file($source)) {
         if (is_file($dest)) {
             $this->putWarning("Cannot copy {$source}. File already exists.");
             return false;
         } else {
             return copy($source, $dest);
         }
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest, $permissions);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         $this->copyRecursive("{$source}/{$entry}", "{$dest}/{$entry}");
     }
     // Clean up
     $dir->close();
     return true;
 }
 /**
  * The method that runs the task
  *
  * @return void
  */
 public function main()
 {
     parent::main();
     // Do we need to create directories?
     if (isset($this->map['mkdir'])) {
         foreach ($this->map['mkdir'] as $dir) {
             $path = realpath($this->destinationBasePath . '/' . $dir);
             if (file_exists($path)) {
                 $this->remove($path);
             }
             $path = $this->destinationBasePath . '/' . $dir;
             $this->log('Creating directory: ' . $path);
             mkdir($path);
         }
     }
     foreach ($this->map['symlinks'] as $item) {
         $item = explode(' ', $item);
         $source = $item[0];
         $destination = $item[1];
         // Normalise paths
         $source = realpath($this->sourceBasePath . '/' . $source);
         $destination = rtrim($this->destinationBasePath, '/') . '/' . $destination;
         if (!file_exists($source)) {
             throw new Exception("Symlink target not found: " . $this->sourceBasePath . '/' . $source, 1);
         }
         // Check if the destination exists and remove it
         if (file_exists($destination)) {
             $destination = rtrim($destination, '/');
             $this->remove($destination);
         }
         // Create the new symlink
         $this->log('Creating Symlink: ' . $destination);
         symlink($source, $destination);
     }
 }
예제 #11
0
 /**
  * Copy a directory recursively and optionally use a extension whitelist
  *
  * @param string $source
  * @param string $dest
  * @param array $allowedExtensions
  * @return bool|null
  */
 protected function recursiveCopy($source, $dest, $allowedExtensions = [])
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Simple copy for a file
     if (is_file($source)) {
         // Filter files not matching the extension whitelist
         if (!empty($allowedExtensions) and !in_array(pathinfo($source, PATHINFO_EXTENSION), $allowedExtensions)) {
             return null;
         }
         return copy($source, $dest);
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         $this->recursiveCopy("{$source}/{$entry}", "{$dest}/{$entry}", $allowedExtensions);
     }
     // Clean up
     $dir->close();
     return true;
 }
예제 #12
0
 public static function setUpBeforeClass()
 {
     if ('\\' === DIRECTORY_SEPARATOR) {
         self::$linkOnWindows = true;
         $originFile = tempnam(sys_get_temp_dir(), 'li');
         $targetFile = tempnam(sys_get_temp_dir(), 'li');
         if (true !== @link($originFile, $targetFile)) {
             $report = error_get_last();
             if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) {
                 self::$linkOnWindows = false;
             }
         } else {
             @unlink($targetFile);
         }
         self::$symlinkOnWindows = true;
         $originDir = tempnam(sys_get_temp_dir(), 'sl');
         $targetDir = tempnam(sys_get_temp_dir(), 'sl');
         if (true !== @symlink($originDir, $targetDir)) {
             $report = error_get_last();
             if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) {
                 self::$symlinkOnWindows = false;
             }
         } else {
             @unlink($targetDir);
         }
     }
 }
 public static function symlink()
 {
     /* WP FileSystem API does not support symlink creation
        global $wp_filesystem;
        */
     $muplugin = dirname(WPF2B_PATH) . self::$muplugin_rel;
     $symlink = WPMU_PLUGIN_DIR . self::$symlink_rel;
     if (!file_exists(WPMU_PLUGIN_DIR)) {
         if (!mkdir(WPMU_PLUGIN_DIR, 0755, true)) {
             return false;
         }
     }
     if (is_link($symlink) || file_exists($symlink)) {
         // Correct symbolic link
         if (is_link($symlink) && readlink($symlink) === $muplugin) {
             return true;
         } else {
             /* is_writable() does not detect broken symlinks, unlink() must be @muted
                // Incorrect and unwritable
                if ( ! is_writable( $symlink ) ) {
                    return false;
                }
                */
             // Remove symbolic link
             if (!@unlink($symlink)) {
                 return false;
             }
         }
     }
     $linking = symlink($muplugin, $symlink);
     return $linking;
 }
 /**
  * Create symlinks from each plugin to app/webroot
  *
  * @return void
  */
 public function create()
 {
     chdir(realpath(WWW_ROOT));
     $paths = $this->_getPaths();
     foreach ($paths as $plugin => $config) {
         $this->out('Processing plugin: <info>' . $plugin . '</info>');
         if (file_exists($config['public'])) {
             $this->out(sprintf('--> <warning>Path "%s" already exists</warning>', \Nodes\Common::stripRealPaths($config['public'])));
             if (is_link($config['public'])) {
                 $symlinkTarget = readlink($config['public']);
                 $this->out('----> Path is already symlink. (' . $symlinkTarget . ')');
                 if (realpath($config['relative_private']) === realpath($symlinkTarget)) {
                     $this->out('----> <info>Skipping</info>, Already configured correctly');
                     continue;
                 }
                 $this->out('--> <error>Target is already symlink, but does not have same source</error>');
                 continue;
             } elseif (is_file($config['public'])) {
                 $this->out('----> Skipping, target is a file');
                 continue;
             } else {
                 $this->out('----> <error>Skipping, don\'t know how to process file</error>');
                 continue;
             }
         }
         if (symlink($config['relative_private'], $config['relative_public'])) {
             $this->out(sprintf('--> <info>OK</info>, symlink created (%s => %s)', \Nodes\Common::stripRealPaths($config['private']), \Nodes\Common::stripRealPaths($config['public'])));
         } else {
             $this->out('--> <error>Error</error> Could not create symlink');
         }
     }
 }
예제 #15
0
 public function init()
 {
     parent::init();
     $extJsSrcDir = Yii::getAlias($this->extJsDir);
     $extJsSrcExtendDir = Yii::getAlias($this->extJsExtendDir);
     $dstDir = Yii::getAlias($this->dstPath);
     $extJsDstDir = $dstDir . DIRECTORY_SEPARATOR . 'extjs';
     $extJsExtendDstDir = $dstDir . DIRECTORY_SEPARATOR . 'extjs-extend';
     if (!is_dir($dstDir)) {
         if (!is_dir($dstDir)) {
             FileHelper::createDirectory($dstDir);
         }
     }
     if (!is_dir($extJsDstDir)) {
         symlink($extJsSrcDir, $extJsDstDir);
     }
     if (!is_dir($extJsExtendDstDir)) {
         symlink($extJsSrcExtendDir, $extJsExtendDstDir);
     }
     $data = DpConfig::find()->all();
     $config = [];
     foreach ($data as $item) {
         $config[$item['name']] = $item['value'];
     }
     $this->config = $config;
     $this->identity = Yii::$app->user->identity;
 }
 public static function postInstall(Event $event)
 {
     // Check if a config.json file exists, copy the config.dist.json if not
     if (!file_exists('App/Config/config.json')) {
         copy('App/Config/config.dist.json', 'App/Config/config.json');
     }
     // Make sure the assets directory exists
     if (!is_dir('www/assets')) {
         mkdir('www/assets', 0755);
     }
     // Symlink img
     $bsImagePath = '../../vendor/twbs/bootstrap/docs/assets/img';
     $imgAssetsPath = 'www/assets/img';
     if (!file_exists($imgAssetsPath)) {
         symlink($bsImagePath, $imgAssetsPath);
     }
     // Symlink js
     $bsJSPath = '../../vendor/twbs/bootstrap/docs/assets/js';
     $jsAssetsPath = 'www/assets/js';
     if (!file_exists($jsAssetsPath)) {
         symlink($bsJSPath, $jsAssetsPath);
     }
     // Symlink css
     $bsCSSPath = '../../vendor/twbs/bootstrap/docs/assets/css';
     $cssAssetsPath = 'www/assets/css';
     if (!file_exists($cssAssetsPath)) {
         symlink($bsCSSPath, $cssAssetsPath);
     }
 }
예제 #17
0
/**
 * Recursively copies from one directory to another
 *
 * @access	public
 * @param 	string
 * @param 	string
 * @return	array
 */
function copyr($source, $dest)
{
    // Simple copy for a file
    if (is_file($source)) {
        return copy($source, $dest);
    }
    // Make destination directory
    if (!is_dir($dest)) {
        mkdir($dest);
    }
    // If the source is a symlink
    if (is_link($source)) {
        $link_dest = readlink($source);
        return symlink($link_dest, $dest);
    }
    // Loop through the folder
    $dir = dir($source);
    if (!is_object($dir)) {
        return FALSE;
    }
    while (false !== ($entry = $dir->read())) {
        // Skip pointers
        if ($entry == '.' or $entry == '..') {
            continue;
        }
        // Deep copy directories
        if ($dest !== "{$source}/{$entry}") {
            copyr("{$source}/{$entry}", "{$dest}/{$entry}");
        }
    }
    // Clean up
    $dir->close();
    return true;
}
예제 #18
0
파일: IO.php 프로젝트: nojacko/twuddle-core
 /**
  * Copy all folders and files in given path to another location.
  * @param string $source Directory to copy.
  * @param string $dest Directory to copy $source to.
  * @param bool $recursive Should it be created recursively. 
  * @return bool true if successfull, otherwise false.
  */
 public static function copy($source, $dest, $recursive = false)
 {
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Simple copy for a file
     if (is_file($source)) {
         return @copy($source, $dest);
     }
     // It's a directoy, should we recurse?
     if (false === $recursive) {
         return false;
     }
     // Make destination directory
     if (false === is_dir($dest)) {
         mkdir($dest);
     }
     // Loop through the folder
     if ($dir = @dir($source)) {
         while (false !== ($entry = $dir->read())) {
             // Skip pointers
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             // Deep copy directories
             $this->copy($source . DIRECTORY_SEPARATOR . $entry, $dest . DIRECTORY_SEPARATOR . $entry);
         }
         // Clean up
         $dir->close();
         return true;
     }
     return false;
 }
예제 #19
0
function symlink_force($source, $dest)
{
    if (file_exists($dest)) {
        unlink($dest);
    }
    symlink($source, $dest);
}
예제 #20
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->setupBuildDir($output);
     $modules = $this->getModulesToProcess($input);
     $manager = $this->neptune['assets'];
     foreach ($modules as $name => $module) {
         $output->writeln('');
         $config = $this->neptune['config'];
         if (!($command = $config->get("{$name}.assets.build_cmd", false))) {
             $output->writeln("Skipping <info>{$name}</info>");
             continue;
         }
         $output->writeln("Building <info>{$name}</info>");
         $dir = $module->getDirectory();
         passthru("cd {$dir} && {$command}");
         //move built assets into public dir
         $build_dir = $dir . 'assets_built/';
         if (!file_exists($build_dir)) {
             throw new \Exception(sprintf('Assets build command for "%s" must create directory "%s"', $name, $build_dir));
         }
         $public_dir = $this->neptune->getRootDirectory() . 'public/assets/';
         $group_dir = $public_dir . $name;
         if (file_exists($group_dir)) {
             unlink($group_dir);
         }
         symlink($build_dir, $group_dir);
         $output->writeln(sprintf('Linking %s to %s', $build_dir, $group_dir));
         //generate concatenated asset files
         $manager->concatenateAssets($name, $public_dir);
         $output->writeln('Creating concatenated group files');
     }
     $output->writeln('');
     $output->writeln(sprintf('Built assets to <info>%s</info>', $this->build_dir));
 }
예제 #21
0
 /**
  * Create the symlink doc/book/index.md pointing to repo README.md
  */
 private function symlinkReadmeToIndex()
 {
     $rootDir = getcwd();
     chdir('doc/book');
     symlink('../../README.md', 'index.md');
     chdir($rootDir);
 }
예제 #22
0
 public function symlink($target, $link, $force = false)
 {
     if ($force) {
         return @symlink($target, $link);
     }
     return symlink($target, $link);
 }
예제 #23
0
 function copyr($source, $dest)
 {
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     if (is_file($source)) {
         $copied = copy($source, $dest);
         $content = file_get_contents($dest);
         $content = str_replace("Forone\\Admin\\Controllers", "App\\Http\\Controllers\\Forone\\Admin\\Controllers", $content);
         file_put_contents($dest, $content);
         return $copied;
     }
     if (!is_dir($dest)) {
         mkdir($dest, 0777, true);
     }
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         copyr("{$source}/{$entry}", "{$dest}/{$entry}");
     }
     $dir->close();
     return true;
 }
예제 #24
0
function categorize($afile, $category, $alink)
{
    //todo: sha hash rename
    global $OperatingSystem;
    $old_path = getcwd();
    chdir(categoriesPath . '/' . $category);
    $afile = '../' . storageDir . '/' . $afile;
    error_log("afile:" . $afile);
    error_log("alink:" . $alink);
    try {
        switch ($OperatingSystem) {
            case windows:
                file_exists($alink) ? $ret = true : ($ret = symlinkWindows('../' . $afile, $alink));
                break;
                //symlink is not reliable under windows and is supposed to work with fullpaths
            //symlink is not reliable under windows and is supposed to work with fullpaths
            case linux:
                file_exists($alink) ? $ret = true : ($ret = symlink('../' . $afile, $alink));
                break;
            case mac:
                file_exists($alink) ? $ret = true : ($ret = symlink('../' . $afile, $alink));
                break;
                //@todo perhaps works the same as for linux
        }
    } catch (ErrorException $e) {
        $ret = copy('../' . $afile, $alink);
    }
    chdir($old_path);
    return $ret;
}
 /**
  * @param string $source
  * @param string $target
  * @param bool $copyOnFailure
  * @param bool $makeRelative Create a relative link instead of an absolute
  */
 public function symlink($source, $target, $copyOnFailure = TRUE, $makeRelative = TRUE)
 {
     if (!file_exists($source)) {
         throw new \InvalidArgumentException('The symlink source "' . $source . '" is not available.');
     }
     if (file_exists($target)) {
         throw new \InvalidArgumentException('The symlink target "' . $target . '" already exists.');
     }
     // As Windows needs a relative path with backslashes, we ensure the proper directory separator is used
     $symlinkSource = strtr($makeRelative ? $this->findShortestPath($target, $source) : $source, '/', DIRECTORY_SEPARATOR);
     $symlinkTarget = strtr($target, '/', DIRECTORY_SEPARATOR);
     $symlinkSuccessfull = @symlink($symlinkSource, $symlinkTarget);
     $additionalErrorInformation = '';
     if (!$symlinkSuccessfull && !stristr(PHP_OS, 'darwin') && !stristr(PHP_OS, 'cygwin') && stristr(PHP_OS, 'win')) {
         // Try fallback to mklink for Windows, because symlink can't handle relative paths starting with "..\"
         $output = NULL;
         $parameter = is_dir($source) ? ' /D' : '';
         $symlinkSuccessfull = $this->getProcess()->execute('mklink' . $parameter . ' ' . escapeshellarg($symlinkTarget) . ' ' . escapeshellarg($symlinkSource), $output) === 0;
         if (!$symlinkSuccessfull) {
             $additionalErrorInformation = PHP_EOL . ' ' . PHP_EOL . 'Windows system detected - please ensure you are running the Composer command with administrator rights to be able to create symlinks.';
         }
     }
     if (!$symlinkSuccessfull && !$copyOnFailure) {
         throw new \RuntimeException('Symlinking target "' . $symlinkTarget . '" to source "' . $symlinkSource . '" ("' . $source . '")  failed.' . $additionalErrorInformation, 1430494084);
     } elseif (!$symlinkSuccessfull && $copyOnFailure) {
         try {
             $this->copy($symlinkSource, $symlinkTarget);
         } catch (\Exception $exception) {
             throw new \RuntimeException('Neither symlinking nor copying target "' . $symlinkTarget . '" to source "' . $symlinkSource . '" ("' . $source . '") worked.' . $additionalErrorInformation, 1430494090);
         }
     }
 }
예제 #26
0
 /**
  * @param string $baseDirectory
  * @param string $targetDirectory
  * @param boolean $useMinified
  * @return string
  * @throws HelperException
  */
 public static function getFrontendUrl($baseDirectory = NULL, $targetDirectory = 'scripts', $useMinified = TRUE)
 {
     $ds = DIRECTORY_SEPARATOR;
     $source = realpath(__DIR__ . $ds . '..' . $ds . '..') . $ds . 'javascript' . $ds . 'rsa' . ($useMinified ? '.min' : '') . '.js';
     $file = $targetDirectory . '/rsa' . ($useMinified ? '.min' : '') . '.' . filemtime($source) . '.js';
     if (!$baseDirectory) {
         $baseDirectory = $_SERVER['DOCUMENT_ROOT'];
     }
     $target = $baseDirectory . $ds . $file;
     if (!is_file($target)) {
         $dir = dirname($target);
         if (!is_dir($dir)) {
             mkdir($dir, 0777, TRUE);
             if (!is_dir($dir)) {
                 throw new HelperException("Cannot auto-publish '{$file}', please do so manually");
             }
         }
         if (!symlink($source, $target)) {
             if (!copy($source, $target)) {
                 throw new HelperException("Cannot auto-publish '{$file}', please do so manually");
             }
         }
     }
     return $file;
 }
/**
 * Copy a file, or recursively copy a folder and its contents
 *
 * @author      Aidan Lister <*****@*****.**>
 * @version     1.0.1
 * @link        http://aidanlister.com/2004/04/recursively-copying-directories-in-php/
 * @param       string   $source    Source path
 * @param       string   $dest      Destination path
 * @return      bool     Returns TRUE on success, FALSE on failure
 */
function copyr($source, $dest)
{
    // Check for symlinks
    if (is_link($source)) {
        return symlink(readlink($source), $dest);
    }
    // Simple copy for a file
    if (is_file($source)) {
        return copy($source, $dest);
    }
    // Make destination directory
    if (!is_dir($dest)) {
        mkdir($dest);
    }
    // Loop through the folder
    $dir = dir($source);
    while (false !== ($entry = $dir->read())) {
        // Skip pointers
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        // Deep copy directories
        copyr("{$source}/{$entry}", "{$dest}/{$entry}");
    }
    // Clean up
    $dir->close();
    return true;
}
 public function make($object, $recursive = true)
 {
     $this->checkDirectory();
     if (!$object) {
         $this->safeClean();
         return $this->directory;
     }
     $realDirectory = null;
     if (is_link($this->directory)) {
         $realDirectory = readlink($this->directory);
         if ($realDirectory === false) {
             throw new WrongStateException('invalid pointer: ' . $this->directory);
         }
     }
     $reversePath = $this->identityMap->reverseLookup($object);
     if (!$reversePath && is_link($this->directory)) {
         throw new WrongStateException('you must always store your object somewhere ' . 'before you going to update pointer ' . $this->directory);
     }
     if ($reversePath && file_exists($this->directory) && !$realDirectory && $this->directory != $reversePath) {
         throw new WrongStateException('you should relocate object ' . $this->directory . ' to ' . $reversePath . ' by yourself.' . ' cannot replace object with a link');
     }
     if ($reversePath && (!file_exists($this->directory) || $realDirectory)) {
         if (!$realDirectory || $realDirectory != $reversePath) {
             $this->safeClean();
             $status = symlink($reversePath, $this->directory);
             if ($status !== true) {
                 throw new WrongStateException('error creating symlink');
             }
         }
         return $reversePath;
     }
     $result = parent::make($object, $recursive);
     $this->identityMap->bind($result, $object);
     return $result;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     # MVC object
     $mvc = MVCStore::retrieve('mvc');
     if ($input->getArgument('folder') == 'web') {
         $input->setArgument('folder', dirname($mvc->getAppDir()) . '/web');
     }
     $folderArg = rtrim($input->getArgument('folder'), '/');
     if (!is_dir($folderArg)) {
         throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('folder')));
     }
     $modulesPath = $folderArg . '/modules/';
     @mkdir($modulesPath);
     if ($input->getOption('symlinks')) {
         $output->writeln('Trying to install assets as <comment>symbolic links</comment>.');
     } else {
         $output->writeln('Installing assets as <comment>hard copies</comment>.');
     }
     foreach ($mvc->getModules() as $module) {
         if (is_dir($originDir = $module->getPath() . '/Resources/public')) {
             $targetDir = $modulesPath . preg_replace('/module$/', '', strtolower($module->getName()));
             $output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', $module->getNamespace(), $targetDir));
             if (!$this->recursiveRemoveDir($targetDir)) {
                 $output->writeln(sprintf('Could\'t been removed the dir "%s".', $targetDir));
             }
             if ($input->getOption('symlinks')) {
                 #link($originDir, $targetDir);
                 @symlink($originDir, $targetDir);
             } else {
                 $this->resourceCopy($originDir, $targetDir);
             }
         }
     }
 }
예제 #30
0
 /**
  * Given /^I copy all files from "(?P<source>.*)" to "(?P<destination>.)*)"$/
  */
 public function recursiveCopy($source, $dest, $permissions = 0755)
 {
     $this->_logger()->logInfo("Copying: {$source} to {$dest}");
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $dest);
     }
     // Simple copy for a file
     if (is_file($source)) {
         return copy($source, $dest);
     }
     // Make destination directory
     if (!is_dir($dest)) {
         mkdir($dest, $permissions);
     }
     // Loop through the folder
     $dir = dir($source);
     while (false !== ($entry = $dir->read())) {
         // Skip pointers
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         // Deep copy directories
         if (!$this->recursiveCopy("{$source}/{$entry}", "{$dest}/{$entry}")) {
             // Error!
             return false;
         }
     }
     // Clean up
     $dir->close();
     return true;
 }