Development

Changeset 13319

You must first sign up to be able to contribute.

Changeset 13319

Show
Ignore:
Timestamp:
11/24/08 23:05:41 (7 months ago)
Author:
FabianLange
Message:

[1.2] fixed relative symlinks that were incorrectly when some directories had the same prefix. added plenty tests for this.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/lib/task/sfFilesystem.class.php

    r12858 r13319  
    352352  protected function calculateRelativeDir($from, $to) 
    353353  { 
    354     $commonChars = 0; 
     354    $commonDirs = 0; 
    355355    $minPathLength = min(strlen($from), strlen($to)); 
     356 
    356357    // count how many chars the strings have in common 
    357     while ($commonChars < $minPathLength) 
    358     { 
    359       if ($from[$commonChars] != $to[$commonChars]) break; 
    360       $commonChars++; 
    361     } 
    362     if ($commonChars) 
    363     { 
    364       $levelUp = substr_count($from, DIRECTORY_SEPARATOR, $commonChars); 
     358    $pos = 0; 
     359    while ($pos < $minPathLength) 
     360    { 
     361      if ($from[$pos] != $to[$pos]) break; 
     362      if ($from[$pos++] == DIRECTORY_SEPARATOR) $commonDirs = $pos; 
     363    } 
     364    if ($commonDirs) 
     365    { 
     366      $levelUp = substr_count($from, DIRECTORY_SEPARATOR, $commonDirs); 
    365367      // up that many level 
    366368      $relativeDir  = str_repeat("..".DIRECTORY_SEPARATOR, $levelUp); 
    367369      // down the remaining $to path 
    368       $relativeDir .= substr($to, $commonChars); 
     370      $relativeDir .= substr($to, $commonDirs); 
    369371      return $relativeDir; 
    370372    } 
  • branches/1.2/test/unit/task/sfFilesystemTest.php

    r12850 r13319  
    1010require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1111 
     12//lazy constant, cause it is so often used in this test 
     13define("DS", DIRECTORY_SEPARATOR); 
     14 
    1215class myFilesystem extends sfFilesystem 
    1316{ 
     
    1821} 
    1922 
    20 $t = new lime_test(3, new lime_output_color()); 
     23$t = new lime_test(6, new lime_output_color()); 
    2124 
    2225$dispatcher = new sfEventDispatcher(); 
     
    2427 
    2528$t->diag('sfFilesystem calculates relative pathes'); 
    26 $common = DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'sfproject'.DIRECTORY_SEPARATOR
    27 $source = $common.'web'.DIRECTORY_SEPARATOR.'myplugin'; 
    28 $target = $common.'plugins'.DIRECTORY_SEPARATOR.'myplugin'.DIRECTORY_SEPARATOR.'web'; 
    29 $t->is($filesystem->calculateRelativeDir($source, $target), '..'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'myplugin'.DIRECTORY_SEPARATOR.'web', '->calculateRelativeDir() correctly calculates the relative path'); 
     29$common = DS.'tmp'.DS.'sfproject'.DS
     30$source = $common.'web'.DS.'myplugin'; 
     31$target = $common.'plugins'.DS.'myplugin'.DS.'web'; 
     32$t->is($filesystem->calculateRelativeDir($source, $target), '..'.DS.'plugins'.DS.'myplugin'.DS.'web', '->calculateRelativeDir() correctly calculates the relative path'); 
    3033 
    31 $source = $common.'web'.DIRECTORY_SEPARATOR.'myplugin'; 
    32 $target = $common.'web'.DIRECTORY_SEPARATOR.'otherplugin'.DIRECTORY_SEPARATOR.'sub'; 
    33 $t->is($filesystem->calculateRelativeDir($source, $target), 'otherplugin'.DIRECTORY_SEPARATOR.'sub', '->calculateRelativeDir() works without going up one dir'); 
     34$source = $common.'web'.DS.'myplugin'; 
     35$target = $common.'webplugins'.DS.'myplugin'.DS.'web'; 
     36$t->is($filesystem->calculateRelativeDir($source, $target), '..'.DS.'webplugins'.DS.'myplugin'.DS.'web', '->calculateRelativeDir() correctly calculates the relative path for dirs that share chars'); 
     37 
     38$source = $common.'web'.DS.'myplugin'; 
     39$target = $common.'web'.DS.'otherplugin'.DS.'sub'; 
     40$t->is($filesystem->calculateRelativeDir($source, $target), 'otherplugin'.DS.'sub', '->calculateRelativeDir() works without going up one dir'); 
    3441 
    3542$source = 'c:\sfproject\web\myplugin'; 
    3643$target = 'd:\symfony\plugins\myplugin\web'; 
    3744$t->is($filesystem->calculateRelativeDir($source, $target), 'd:\symfony\plugins\myplugin\web', '->calculateRelativeDir() returns absolute path when no relative path possible'); 
     45 
     46$source = $common.'web'.DS.'myplugin'; 
     47$target = $common.'web'.DS.'myotherplugin'.DS.'sub'; 
     48$t->is($filesystem->calculateRelativeDir($source, $target), 'myotherplugin'.DS.'sub', '->calculateRelativeDir() correctly calculates the relative path for dirs that share chars'); 
     49 
     50$source = $common.'web'.DS.'myplugin'; 
     51$target = $common.'web'.DS.'motherplugin'.DS.'sub'; 
     52$t->is($filesystem->calculateRelativeDir($source, $target), 'motherplugin'.DS.'sub', '->calculateRelativeDir() correctly calculates the relative path for dirs that share chars'); 

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.