Changeset 3246

Show
Ignore:
Timestamp:
11/29/06 21:35:16 (6 years ago)
Author:
gregmac
Message:

Fix bug with md5 checking in install_amp; Add detection for whitespace-only differences

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/install_amp

    r3245 r3246  
    194194      case "d":  
    195195        out(""); 
    196         passthru("diff -u ".$file2." ".$file1); 
     196        // w = ignore whitespace, u = unified 
     197        passthru("diff -wu ".escapeshellarg($file2)." ".escapeshellarg($file1)); 
    197198      break; 
    198199      case "s": 
     
    232233} 
    233234 
     235function checkDiff($file1, $file2) { 
     236  // diff, ignore whitespace and be quiet 
     237  exec("diff -wq ".escapeshellarg($file2)." ".escapeshellarg($file1), $output, $retVal); 
     238  return ($retVal != 0); 
     239} 
     240 
    234241function amp_mkdir($directory, $mode = "0755", $recursive = false) { 
    235242  debug("mkdir ".$directory.", ".$mode); 
     
    297304      $destination=str_replace("/agi-bin",trim($asterisk_conf["astagidir"]),$destination); 
    298305      $destination=str_replace("/sounds",trim($asterisk_conf["astvarlibdir"])."/sounds",$destination); 
    299        
     306 
    300307      // if this is a directory, ensure destination exists 
    301308      if (is_dir($source)) { 
     
    307314      } 
    308315       
     316      //var_dump($md5sums); 
    309317      if (!is_dir($source)) { 
    310         if ($check_md5s && file_exists($destination) && isset($md5sums[$destination]) && (md5_file($destination) != $md5sums[$destination])) { 
    311           $overwrite = ask_overwrite($source, $destination, $md5sums); 
     318        $md5_source = preg_replace("|^/?amp_conf/|", "/", $source); 
     319 
     320        if ($check_md5s && file_exists($destination) && isset($md5sums[$md5_source]) && (md5_file($destination) != $md5sums[$md5_source])) { 
     321          // double check using diff utility (and ignoring whitespace) 
     322          // This is a somewhat edge case (eg, the file doesn't match 
     323          // it's md5 sum from the previous version, but no substantial 
     324          // changes exist compared to the current version), but it  
     325          // pervents a useless prompt to the user. 
     326          if (checkDiff($source, $destination)) { 
     327            $overwrite = ask_overwrite($source, $destination); 
     328          } else { 
     329            debug("NOTE: MD5 for ".$destination." was different, but `diff` did not detect any (non-whitespace) changes: overwriting"); 
     330            $overwrite = true; 
     331          } 
    312332        } else { 
    313333          $overwrite = true;