未验证 提交 d479ac66 编写于 作者: Q qkqpttgf 提交者: GitHub

fix: update in windows system(slash)

上级 1b04aafd
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册