From d479ac66626bb4ae817e40a4d58e865a677d2a38 Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Thu, 27 Aug 2020 09:19:20 +0800 Subject: [PATCH] fix: update in windows system(slash) --- platform/Normal.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/platform/Normal.php b/platform/Normal.php index fa1ab1f..e5e3d8e 100644 --- a/platform/Normal.php +++ b/platform/Normal.php @@ -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); -- GitLab