elviss 2 年之前
父節點
當前提交
2bd5d1db8b
共有 2 個文件被更改,包括 19 次插入17 次删除
  1. 8 6
      src/PackageClass.php
  2. 11 11
      src/Utility.php

+ 8 - 6
src/PackageClass.php

@@ -154,6 +154,7 @@ class PackageClass
 			"repoName" => $pkg->getName(),
 			"version" => $pkg->getPrettyVersion(),
 			"cacheDir" => $cacheDir,
+			"toolDir" => $config['tool-dir'],
 			"ossHost" => $config['oss-host'],
 			"moduleName" => $moduleName,
 			"commonDir" => $commonDir,
@@ -166,6 +167,7 @@ class PackageClass
 	//下载包module文件
 	private static function fetchModuleFiles($packageInfo)
 	{
+		$toolDir = $packageInfo['toolDir'];
 		$cacheDir = $packageInfo['cacheDir'];
 		$repoName = $packageInfo['repoName'];
 		$version = $packageInfo['version'];
@@ -182,7 +184,7 @@ class PackageClass
 			logInfo($repoName,"fetching module file -- ",$fileName);
 
 			//下载文件到缓存区
-			$filePath = downloadToDir($ossHost,$repoName,$version,$fileName,$cacheDir);
+			$filePath = downloadToDir($toolDir,$ossHost,$repoName,$version,$fileName,$cacheDir);
 			if(! $filePath ){
 				logError($repoName,"fetch module file failed",$fileName);
 				return false;
@@ -190,7 +192,7 @@ class PackageClass
 
 			// 解压文件
 			if( isZipFile($fileName) ){
-				if(! unzipFile($filePath,$moduleDir)) {
+				if(! unzipFile($toolDir,$filePath,$moduleDir)) {
 					logError($repoName,"unzip module file failed",$fileName);
 					return false;
 				}
@@ -202,9 +204,10 @@ class PackageClass
 	//下载包common文件
 	private static function fetchCommonFiles($packageInfo)
 	{
+		$toolDir = $packageInfo['toolDir'];
 		$cacheDir = $packageInfo['cacheDir'];
 		$repoName = $packageInfo['repoName'];
-		$version = $packageInfo['version'];
+		$version  = $packageInfo['version'];
 		$commonDir = $packageInfo['commonDir'];
 		$ossHost = $packageInfo['ossHost'];
 		$commonFiles = $packageInfo['helper']['common-files'];
@@ -215,7 +218,7 @@ class PackageClass
 			$fileName = $fileInfo['name'];
 			logInfo($repoName,"fetching common file -- ",$fileName);
 			//下载文件到缓存区
-			$filePath = downloadToDir($ossHost,$repoName,$version,$fileName,$cacheDir);
+			$filePath = downloadToDir($toolDir,$ossHost,$repoName,$version,$fileName,$cacheDir);
 			if(! $filePath ){
 				logError($repoName,"fetch common file failed",$fileName);
 				continue;
@@ -223,7 +226,7 @@ class PackageClass
 
 			// 解压文件
 			if( isZipFile($fileName) ){
-				if(! unzipFile($filePath,$commonDir)) {
+				if(! unzipFile($toolDir,$filePath,$commonDir)) {
 					logError($repoName,"unzip common file failed",$fileName);
 					return false;
 				}
@@ -242,7 +245,6 @@ class PackageClass
 		$ossHost = $packageInfo['ossHost'];
 		$configFiles = $packageInfo['helper']['config-files'];
 		if(! $configFiles){
-			logInfo($repoName,'no config files defined. skip.');
 			return;
 		}
 		foreach($configFiles as $fileInfo){

+ 11 - 11
src/Utility.php

@@ -1,7 +1,7 @@
 <?php
 //记录信息日志
 function logInfo(){
-	$content = '[INFO]';
+	$content = '[INF]';
 	$args = func_get_args();
 	$argc = func_num_args();
 	for($i=0;$i<$argc;$i++){
@@ -50,13 +50,13 @@ function isZipFile($fileName){
 	return in_array($fileExt,array("zip","7z"));
 }
 //获取 gopeed.exe 路径
-function getGoPeedPath(){
-	return dirname(dirname(__FILE__)). "/bin/gopeed.exe";
+function getGoPeedPath($toolDir){
+	return pathJoin($toolDir,"gopeed.exe");
 }
 
 //获取 7z.exe 路径
-function get7ZipPath(){
-	return dirname(dirname(__FILE__)). "/bin/7z.exe";
+function get7ZipPath($toolDir){
+	return pathJoin($toolDir,"7z.exe");
 }
 //两个参数的路径拼接
 function twoPathJoin($base, $path) {
@@ -149,7 +149,7 @@ function loadConfig($cfgPath){
 }
 
 //多线程下载文件
-function downloadToDir($ossHost,$repoName,$fileName,$targetDir){
+function downloadToDir($toolDir,$ossHost,$repoName,$repoVersion,$fileName,$targetDir){
 	if (!file_exists($targetDir)){
 		mkdir($targetDir,0777,true);
 	}
@@ -158,9 +158,9 @@ function downloadToDir($ossHost,$repoName,$fileName,$targetDir){
 	if( file_exists($targetPath) ) {
 		return $targetPath;
 	}
-	$gopeed = getGoPeedPath();
+	$gopeed = getGoPeedPath($toolDir);
 	
-	$remoteUrl = pathJoin($ossHost,$repoName,$fileName);
+	$remoteUrl = pathJoin($ossHost,$repoName,$repoVersion,$fileName);
 	$cmd = $gopeed." -D=" . $targetDir . " " . $remoteUrl;
 	system($cmd, $ret);
 	if ($ret != 0) {
@@ -170,7 +170,7 @@ function downloadToDir($ossHost,$repoName,$fileName,$targetDir){
 }
 
 //解压缩文件
-function unzipFile($zipFile, $targetDir){
+function unzipFile($toolDir,$zipFile, $targetDir){
 	$fileExt = getFileExt($zipFile);
 	if($fileExt == "zip"){
 		$zip= new \ZipArchive;
@@ -184,8 +184,8 @@ function unzipFile($zipFile, $targetDir){
 		}
 	}
 	if($fileExt == "7z"){
-		$sevenZip = get7ZipPath();
-		$logPath = $zipFile . '.7zlog';
+		$sevenZip = get7ZipPath($toolDir);
+		$logPath = $zipFile . '.log';
 		$cmd = $sevenZip . " x $zipFile -o$targetDir -aoa > " . $logPath;
 		system($cmd, $ret);
 		if ($ret != 0) {