Ejemplo n.º 1
0
 /**
  * Creates a symlink to the given destination
  * 
  * @param string|Path $destination
  */
 public function linkTo($destination)
 {
     $target = new FileDescriptor($destination);
     $targetDir = new Directory($target->getDirname());
     $targetDir->make();
     $ok = false;
     if ($target->isLink()) {
         if (!$target->getLinkTarget()->equals($this->pathname)) {
             $target->delete();
         } else {
             $ok = true;
         }
     }
     if (!$ok && @symlink($this->pathname, $target->getPathname()) !== true) {
         $report = error_get_last();
         if (is_array($report) && DIRECTORY_SEPARATOR === '\\' && strpos($report['message'], 'error code(1314)') !== false) {
             throw new FileException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
         }
         throw new FileException(sprintf('Failed to create symbolic link from %s to %s', $this->pathname, $targetDir));
     }
 }