Skip to content

Commit e61c42f

Browse files
committed
改进一下自动升级的脚本,创建一个唯一的临时目录作为文件下载的目标目录
1 parent 43f3432 commit e61c42f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

sapi/lib/helper.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function swoole_cli_self_update()
1717
if (strstr($uname, 'x86_64') !== false) {
1818
$arch = 'x64';
1919
} elseif (strstr($uname, 'aarch64') !== false) {
20-
$arch = 'aarch64';
20+
$arch = 'arm64';
2121
} else {
2222
echo "unsupported architecture\n";
2323
return;
@@ -39,19 +39,25 @@ function swoole_cli_self_update()
3939
echo "The current version `v" . SWOOLE_VERSION . "-{$arch}` is already the latest\n";
4040
} else {
4141
echo "Upgrading to version v{$match[1]}\n";
42-
$tmpFile = "/tmp/{$newVersion->filename}";
42+
$taskId = uniqid('swoole-cli-update-');
43+
$tmpDir = "/tmp/{$taskId}";
44+
$tmpFile = $tmpDir . "/{$newVersion->filename}";
45+
mkdir($tmpDir, 0755, true);
4346
echo `wget -O {$tmpFile} {$newVersion->url}`, PHP_EOL;
4447
if (!is_file($tmpFile) or filesize($tmpFile) !== intval($newVersion->size)) {
4548
echo "Failed to download {$newVersion->url}\n";
4649
return;
4750
}
48-
echo `cd /tmp && tar xvf {$newVersion->filename}`, PHP_EOL;
51+
echo `cd $tmpDir && tar xvf {$newVersion->filename}`, PHP_EOL;
4952

50-
$tmpBinFile = '/tmp/swoole-cli';
53+
$tmpBinFile = "$tmpDir/swoole-cli";
5154
if (!is_file($tmpBinFile) or filesize($tmpBinFile) == 0) {
5255
echo "Failed to decompress archive {$newVersion->filename}\n";
5356
return;
5457
}
55-
echo `mv /tmp/swoole-cli $binFile`;
58+
echo `mv $tmpBinFile $binFile`;
59+
echo `rm -rf $tmpDir`;
60+
echo `chmod +x $binFile`;
61+
echo "Upgrade completed\n";
5662
}
5763
}

sapi/lib/upgrade.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
include __DIR__ . '/helper.php';
3+
swoole_cli_self_update();

0 commit comments

Comments
 (0)