1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 02:34:39 +01:00

Improve phar installer

This commit is contained in:
Daniil Gentili 2021-12-13 14:55:50 +01:00
parent c52f0578df
commit dffc8eeaa4
3 changed files with 16 additions and 8 deletions

2
docs

@ -1 +1 @@
Subproject commit 0b0c17a38bf999b500d0865230d547e28b3aefa0
Subproject commit 3b8c3e487f92aaf4154fb3e72312dfd4d6a57f2d

View File

@ -958,8 +958,7 @@ abstract class Tools extends StrTools
public static function &getVar($obj, string $var)
{
return \Closure::bind(
function &() use ($var)
{
function &() use ($var) {
return $this->{$var};
},
$obj,

View File

@ -15,7 +15,7 @@ if (!\defined('MADELINE_ALLOW_COMPOSER') && \class_exists(\Composer\Autoload\Cla
class Installer
{
const RELEASE_TEMPLATE = 'https://phar.madelineproto.xyz/release%s?v=new';
const PHAR_TEMPLATE = 'https://phar.madelineproto.xyz/madeline%s.phar?v=new';
const PHAR_TEMPLATE = 'https://phar.madelineproto.xyz/madeline%s.phar?v=%s';
/**
* Phar lock instance.
@ -209,8 +209,9 @@ class Installer
public function install()
{
$remote_release = \file_get_contents(MADELINE_RELEASE_URL) ?: null;
$madeline_phar = "madeline-$remote_release.phar";
$madeline_version = "madeline-{$this->version}.phar.version";
if (\file_exists($madeline_version)) {
$local_release = \file_get_contents($madeline_version) ?: null;
} else {
@ -219,7 +220,6 @@ class Installer
}
\define('HAD_MADELINE_PHAR', !!$local_release);
$madeline_phar = "madeline-$remote_release.phar";
if (($remote_release === $local_release && \file_exists($madeline_phar)) || $remote_release === null) {
return self::load($local_release);
}
@ -230,8 +230,16 @@ class Installer
}
if (!\file_exists($madeline_phar)) {
$phar = \file_get_contents(\sprintf(self::PHAR_TEMPLATE, $this->version));
if (!$phar) {
for ($x = 0; $x < 10; $x++) {
$pharTest = \file_get_contents(\sprintf(self::PHAR_TEMPLATE, $this->version, $remote_release.$x));
if ($pharTest && strpos($pharTest, $remote_release) !== false) {
unset($pharTest);
$phar = $pharTest;
break;
}
sleep(1);
}
if (!isset($phar)) {
return self::load($local_release);
}
@ -239,6 +247,7 @@ class Installer
\flock(self::$lock, LOCK_EX);
\fwrite(self::$lock, $phar);
\fflush(self::$lock);
\fseek(self::$lock, 0)
unset($phar);
self::reportComposer($local_release, $remote_release);