fix: update in windows system(slash)
parent
1b04aafd95
commit
d479ac6662
|
@ -272,12 +272,14 @@ function setConfigResponse($response)
|
||||||
|
|
||||||
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
|
||||||
{
|
{
|
||||||
|
$slash = '/';
|
||||||
|
if (strpos(__DIR__, ':')) $slash = '\\';
|
||||||
// __DIR__ is xxx/platform
|
// __DIR__ is xxx/platform
|
||||||
$projectPath = splitlast(__DIR__, '/')[0];
|
$projectPath = splitlast(__DIR__, $slash)[0];
|
||||||
|
|
||||||
// 从github下载对应tar.gz,并解压
|
// 从github下载对应tar.gz,并解压
|
||||||
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
$url = 'https://github.com/' . $auth . '/' . $project . '/tarball/' . urlencode($branch) . '/';
|
||||||
$tarfile = $projectPath.'/github.tar.gz';
|
$tarfile = $projectPath . $slash .'github.tar.gz';
|
||||||
$githubfile = file_get_contents($url);
|
$githubfile = file_get_contents($url);
|
||||||
if (!$githubfile) return 0;
|
if (!$githubfile) return 0;
|
||||||
file_put_contents($tarfile, $githubfile);
|
file_put_contents($tarfile, $githubfile);
|
||||||
|
@ -286,17 +288,17 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
|
||||||
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
|
||||||
} else {
|
} else {
|
||||||
ob_start();
|
ob_start();
|
||||||
passthru('tar -xzvf '.$tarfile,$stat);
|
passthru('tar -xzvf ' . $tarfile, $stat);
|
||||||
ob_get_clean();
|
ob_get_clean();
|
||||||
}
|
}
|
||||||
unlink($tarfile);
|
unlink($tarfile);
|
||||||
|
|
||||||
$outPath = '';
|
$outPath = '';
|
||||||
$tmp = scandir($projectPath);
|
$tmp = scandir($projectPath);
|
||||||
$name = $auth.'-'.$project;
|
$name = $auth . '-' . $project;
|
||||||
foreach ($tmp as $f) {
|
foreach ($tmp as $f) {
|
||||||
if ( substr($f, 0, strlen($name)) == $name) {
|
if ( substr($f, 0, strlen($name)) == $name) {
|
||||||
$outPath = $projectPath . '/' . $f;
|
$outPath = $projectPath . $slash . $f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,23 +306,27 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
|
||||||
if ($outPath=='') return 0;
|
if ($outPath=='') return 0;
|
||||||
|
|
||||||
//unlink($outPath.'/config.php');
|
//unlink($outPath.'/config.php');
|
||||||
rename($projectPath.'/config.php', $outPath.'/config.php');
|
$response = rename($projectPath . $slash . 'config.php', $outPath . $slash . 'config.php');
|
||||||
|
if (!$response) {
|
||||||
return moveFolder($outPath, $projectPath);
|
$tmp1['code'] = "Move Failed";
|
||||||
|
$tmp1['message'] = "Can not move " . $projectPath . $slash . 'config.php' . " to " . $outPath . $slash . 'config.php';
|
||||||
|
return json_encode($tmp1);
|
||||||
|
}
|
||||||
|
return moveFolder($outPath, $projectPath, $slash);
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveFolder($from, $to)
|
function moveFolder($from, $to, $slash)
|
||||||
{
|
{
|
||||||
if (substr($from, -1)=='/') $from = substr($from, 0, -1);
|
if (substr($from, -1)==$slash) $from = substr($from, 0, -1);
|
||||||
if (substr($to, -1)=='/') $to = substr($to, 0, -1);
|
if (substr($to, -1)==$slash) $to = substr($to, 0, -1);
|
||||||
if (!file_exists($to)) mkdir($to, 0777);
|
if (!file_exists($to)) mkdir($to, 0777);
|
||||||
$handler=opendir($from);
|
$handler=opendir($from);
|
||||||
while($filename=readdir($handler)) {
|
while($filename=readdir($handler)) {
|
||||||
if($filename != '.' && $filename != '..'){
|
if($filename != '.' && $filename != '..'){
|
||||||
$fromfile = $from.'/'.$filename;
|
$fromfile = $from . $slash . $filename;
|
||||||
$tofile = $to.'/'.$filename;
|
$tofile = $to . $slash . $filename;
|
||||||
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
|
||||||
$response = moveFolder($fromfile, $tofile);
|
$response = moveFolder($fromfile, $tofile, $slash);
|
||||||
if (api_error(setConfigResponse($response))) return $response;
|
if (api_error(setConfigResponse($response))) return $response;
|
||||||
}else{
|
}else{
|
||||||
//if (file_exists($tofile)) unlink($tofile);
|
//if (file_exists($tofile)) unlink($tofile);
|
||||||
|
|
Loading…
Reference in New Issue