Development

Changeset 12847

You must first sign up to be able to contribute.

Changeset 12847

Show
Ignore:
Timestamp:
11/09/08 20:01:49 (8 months ago)
Author:
FabianLange
Message:

[1.2] needed to move relative path calculation into sfFilesystem to prevent collision with the mirror command

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/lib/plugin/sfSymfonyPluginManager.class.php

    r12843 r12847  
    7373 
    7474      $filesystem = new sfFilesystem(); 
    75       $target = $this->environment->getOption('web_dir').DIRECTORY_SEPARATOR.$plugin; 
    76       $filesystem->symlink($this->getRelativePath($target, $webDir), $target, true); 
     75      $filesystem->relativeSymlink($webDir, $this->environment->getOption('web_dir').DIRECTORY_SEPARATOR.$plugin, true); 
    7776    } 
    7877  } 
     
    173172    return true; 
    174173  } 
    175  
    176   /** 
    177    * Calculates the relative path from one to another directory. 
    178    * If it would go beyond sf_root_dir the absolute path of $to is returned. 
    179    * 
    180    * @param string $from directory from that the relative path shall be calculated 
    181    * @param string $to target directory 
    182    */  
    183   protected function getRelativePath($from, $to) 
    184   { 
    185     $root = $this->environment->getOption('sf_root_dir').DIRECTORY_SEPARATOR; 
    186     if (strstr($from, $root) && strstr($to, $root)) 
    187     { 
    188       $levelUp = substr_count($from, DIRECTORY_SEPARATOR, strlen($root)); 
    189       // up that many level 
    190       $relativePath  = str_repeat("..".DIRECTORY_SEPARATOR, $levelUp); 
    191       // down the remaining $to path 
    192       $relativePath .= substr($to, strlen($root)); 
    193       return $relativePath; 
    194     } 
    195     else 
    196     { 
    197       // $to is outside sf_root_dir so return absolute path 
    198       return $to; 
    199     } 
    200   } 
    201174} 
  • branches/1.2/lib/task/sfFilesystem.class.php

    r9097 r12847  
    227227 
    228228  /** 
     229   * Creates a symbolic link using a relative path if possible. 
     230   * 
     231   * @param string $originDir      The origin directory path 
     232   * @param string $targetDir      The symbolic link name 
     233   * @param bool   $copyOnWindows  Whether to copy files if on windows 
     234   */ 
     235  public function relativeSymlink($originDir, $targetDir, $copyOnWindows = false) 
     236  { 
     237    if (function_exists('symlink') || !$copyOnWindows) 
     238    { 
     239      $originDir = $this->calculateRelativeDir($targetDir, $originDir); 
     240    } 
     241    $this->symlink($originDir, $targetDir, $copyOnWindows); 
     242  } 
     243 
     244  /** 
    229245   * Mirrors a directory to another. 
    230246   * 
     
    326342    $this->dispatcher->notify(new sfEvent($this, 'command.log', array($message))); 
    327343  } 
     344 
     345  /** 
     346   * Calculates the relative path from one to another directory. 
     347   * If they share no common path the absolute target dir is returned 
     348   * 
     349   * @param string $from directory from that the relative path shall be calculated 
     350   * @param string $to target directory 
     351   */  
     352  protected function calculateRelativeDir($from, $to) 
     353  { 
     354    $commonChars = 0; 
     355    $minPathLength = min(strlen($from), strlen($to)); 
     356    // count how many chars the strings have in common 
     357    for ($i = 0; $i < $minPathLength; $i++) 
     358    { 
     359      if ($from[$i] != $to[$i]) break; 
     360      $commonChars++; 
     361    } 
     362    if ($commonChars) 
     363    { 
     364      $levelUp = substr_count($from, DIRECTORY_SEPARATOR, $commonChars); 
     365      // up that many level 
     366      $relativeDir  = str_repeat("..".DIRECTORY_SEPARATOR, $levelUp); 
     367      // down the remaining $to path 
     368      $relativeDir .= substr($to, $commonChars); 
     369      return $relativeDir; 
     370    } 
     371    return $to; 
     372  } 
    328373} 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.