/** * Initializes this resource publishing target * * @return void * @throws Exception */ public function initializeObject() { foreach ($this->options as $key => $value) { $isOptionSet = $this->setOption($key, $value); if (!$isOptionSet) { throw new Exception(sprintf('An unknown option "%s" was specified in the configuration of a resource FileSystemTarget. Please check your settings.', $key), 1436962549); } } if (!is_writable($this->path)) { @Files::createDirectoryRecursively($this->path); } if (!is_dir($this->path) && !is_link($this->path)) { throw new Exception('The directory "' . $this->path . '" which was configured as a publishing target does not exist and could not be created.', 1436962550); } if (!is_writable($this->path)) { throw new Exception('The directory "' . $this->path . '" which was configured as a publishing target is not writable.', 1436962551); } }
public static function createRelativeSymlink($target, $link) { if (is_dir($link)) { self::removeDirectoryRecursively($link); } else { if (file_exists($link)) { self::unlink($link); } } $relativeTargetPath = Files::getRelativePath($link, $target); if (DIRECTORY_SEPARATOR !== '/') { $relativeTargetPath = str_replace('/', '\\', $relativeTargetPath); $flag = is_dir($target) ? '/d' : ''; $output = array(); $return = 0; exec(sprintf('mklink %s %s %s', $flag, escapeshellarg($link), escapeshellarg($relativeTargetPath)), $output, $return); if ($return !== 0) { throw new Exception(sprintf('Error while attempting to create a relative symlink at "%s" pointing to "%s". Make sure you have sufficient privileges and your operating system supports symlinks.', $link, $relativeTargetPath), 1436962557); } return file_exists($link); } else { return \symlink($relativeTargetPath, $link); } }
/** * Publishes the specified directory to this target, with the given relative path. * * @param string $sourcePath Absolute path to the source directory * @param string $relativeTargetPathAndFilename relative path and filename in the target directory * @throws Exception * @return void */ protected function publishDirectory($sourcePath, $relativeTargetPathAndFilename) { $targetPathAndFilename = $this->path . $relativeTargetPathAndFilename; if (@stat($sourcePath) === FALSE) { throw new Exception(sprintf('Could not publish directory "%s" into resource publishing target "%s" because the source is not accessible (file stat failed).', $sourcePath, $this->name), 1436962555); } if (!file_exists(dirname($targetPathAndFilename))) { Files::createDirectoryRecursively(dirname($targetPathAndFilename)); } try { if ($this->relativeSymlinks) { $result = Files::createRelativeSymlink($sourcePath, $targetPathAndFilename); } else { $temporaryTargetPathAndFilename = uniqid($targetPathAndFilename . '.') . '.tmp'; symlink($sourcePath, $temporaryTargetPathAndFilename); $result = rename($temporaryTargetPathAndFilename, $targetPathAndFilename); } } catch (\Exception $exception) { $result = FALSE; } if ($result === FALSE) { throw new Exception(sprintf('Could not publish "%s" into resource publishing target "%s" because the source directory could not be symlinked at target location.', $sourcePath, $this->name), 1436962556, isset($exception) ? $exception : NULL); } $this->systemLogger->log(sprintf('FileSystemSymlinkTarget: Published directory. (target: %s, file: %s)', $this->name, $relativeTargetPathAndFilename), LOG_DEBUG); }