/**
  * 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 TargetException
  * @return void
  */
 protected function publishDirectory($sourcePath, $relativeTargetPathAndFilename)
 {
     $targetPathAndFilename = $this->path . $relativeTargetPathAndFilename;
     if (@stat($sourcePath) === false) {
         throw new TargetException(sprintf('Could not publish directory "%s" into resource publishing target "%s" because the source is not accessible (file stat failed).', $sourcePath, $this->name), 1416244512);
     }
     if (!file_exists(dirname($targetPathAndFilename))) {
         Files::createDirectoryRecursively(dirname($targetPathAndFilename));
     }
     try {
         if (Files::is_link($targetPathAndFilename)) {
             Files::unlink($targetPathAndFilename);
         }
         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 TargetException(sprintf('Could not publish "%s" into resource publishing target "%s" because the source directory could not be symlinked at target location.', $sourcePath, $this->name), 1416244515, isset($exception) ? $exception : null);
     }
     $this->systemLogger->log(sprintf('FileSystemSymlinkTarget: Published directory. (target: %s, file: %s)', $this->name, $relativeTargetPathAndFilename), LOG_DEBUG);
 }