fix: update in windows system(slash)

pull/128/head
qkqpttgf 2020-08-27 09:19:20 +08:00 committed by GitHub
parent 1b04aafd95
commit d479ac6662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 14 deletions

View File

@ -272,12 +272,14 @@ function setConfigResponse($response)
function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch = 'master')
{
$slash = '/';
if (strpos(__DIR__, ':')) $slash = '\\';
// __DIR__ is xxx/platform
$projectPath = splitlast(__DIR__, '/')[0];
$projectPath = splitlast(__DIR__, $slash)[0];
// 从github下载对应tar.gz并解压
$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);
if (!$githubfile) return 0;
file_put_contents($tarfile, $githubfile);
@ -286,17 +288,17 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
$phar->extractTo($projectPath, null, true);//路径 要解压的文件 是否覆盖
} else {
ob_start();
passthru('tar -xzvf '.$tarfile,$stat);
passthru('tar -xzvf ' . $tarfile, $stat);
ob_get_clean();
}
unlink($tarfile);
$outPath = '';
$tmp = scandir($projectPath);
$name = $auth.'-'.$project;
$name = $auth . '-' . $project;
foreach ($tmp as $f) {
if ( substr($f, 0, strlen($name)) == $name) {
$outPath = $projectPath . '/' . $f;
$outPath = $projectPath . $slash . $f;
break;
}
}
@ -304,23 +306,27 @@ function OnekeyUpate($auth = 'qkqpttgf', $project = 'OneManager-php', $branch =
if ($outPath=='') return 0;
//unlink($outPath.'/config.php');
rename($projectPath.'/config.php', $outPath.'/config.php');
return moveFolder($outPath, $projectPath);
$response = rename($projectPath . $slash . 'config.php', $outPath . $slash . 'config.php');
if (!$response) {
$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($to, -1)=='/') $to = substr($to, 0, -1);
if (substr($from, -1)==$slash) $from = substr($from, 0, -1);
if (substr($to, -1)==$slash) $to = substr($to, 0, -1);
if (!file_exists($to)) mkdir($to, 0777);
$handler=opendir($from);
while($filename=readdir($handler)) {
if($filename != '.' && $filename != '..'){
$fromfile = $from.'/'.$filename;
$tofile = $to.'/'.$filename;
$fromfile = $from . $slash . $filename;
$tofile = $to . $slash . $filename;
if(is_dir($fromfile)){// 如果读取的某个对象是文件夹,则递归
$response = moveFolder($fromfile, $tofile);
$response = moveFolder($fromfile, $tofile, $slash);
if (api_error(setConfigResponse($response))) return $response;
}else{
//if (file_exists($tofile)) unlink($tofile);