mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-22 19:11:16 +01:00
Turn the session file into a session directory
This commit is contained in:
parent
006708dda3
commit
29dd777b5b
@ -23,6 +23,8 @@ use danog\MadelineProto\EventHandler;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Settings;
|
||||
use danog\MadelineProto\Settings\Database\Mysql;
|
||||
use danog\MadelineProto\Settings\Database\Postgres;
|
||||
use danog\MadelineProto\Settings\Database\Redis;
|
||||
|
||||
/*
|
||||
* Various ways to load MadelineProto
|
||||
@ -61,7 +63,7 @@ class MyEventHandler extends EventHandler
|
||||
/**
|
||||
* @var DbArray<array>
|
||||
*/
|
||||
protected $dataStoredOnDb;
|
||||
protected DbArray $dataStoredOnDb;
|
||||
|
||||
/**
|
||||
* Get peer(s) where to report errors.
|
||||
|
@ -22,8 +22,6 @@ namespace danog\MadelineProto;
|
||||
|
||||
use danog\MadelineProto\Ipc\Client;
|
||||
|
||||
use function Amp\File\openFile;
|
||||
|
||||
final class APIWrapper
|
||||
{
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@ final class Postgres
|
||||
$result = $connection->query("SELECT * FROM pg_database WHERE datname = '{$db}'");
|
||||
|
||||
// Replace with getRowCount once it gets fixed
|
||||
if (!iterator_to_array($result)) {
|
||||
if (!\iterator_to_array($result)) {
|
||||
$connection->query("
|
||||
CREATE DATABASE {$db}
|
||||
OWNER {$user}
|
||||
|
@ -70,7 +70,7 @@ final class Client extends ClientAbstract
|
||||
$this->logger = $logger;
|
||||
$this->server = $server;
|
||||
$this->session = $session;
|
||||
self::$instances[$session->getLegacySessionPath()] = $this;
|
||||
self::$instances[$session->getSessionDirectoryPath()] = $this;
|
||||
async($this->loopInternal(...));
|
||||
}
|
||||
/**
|
||||
@ -94,8 +94,8 @@ final class Client extends ClientAbstract
|
||||
} catch (Throwable $e) {
|
||||
$this->logger("An error occurred while disconnecting the client: $e");
|
||||
}
|
||||
if (isset(self::$instances[$this->session->getLegacySessionPath()])) {
|
||||
unset(self::$instances[$this->session->getLegacySessionPath()]);
|
||||
if (isset(self::$instances[$this->session->getSessionDirectoryPath()])) {
|
||||
unset(self::$instances[$this->session->getSessionDirectoryPath()]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -83,8 +83,8 @@ use Webmozart\Assert\Assert;
|
||||
include $autoloadPath;
|
||||
}
|
||||
if (MADELINE_WORKER_TYPE === 'madeline-ipc') {
|
||||
$session = new SessionPaths(MADELINE_WORKER_ARGS[0]);
|
||||
if (!file_exists($session->getSessionPath())) {
|
||||
$session = MADELINE_WORKER_ARGS[0];
|
||||
if (!file_exists($session)) {
|
||||
trigger_error("IPC session $session does not exist!", E_USER_ERROR);
|
||||
exit(1);
|
||||
}
|
||||
@ -102,6 +102,7 @@ use Webmozart\Assert\Assert;
|
||||
$runnerId = MADELINE_WORKER_ARGS[1];
|
||||
Assert::numeric($runnerId);
|
||||
$runnerId = (int) $runnerId;
|
||||
$session = new SessionPaths($session);
|
||||
|
||||
try {
|
||||
Magic::start();
|
||||
|
@ -27,8 +27,12 @@ use const LOCK_SH;
|
||||
use const PHP_MAJOR_VERSION;
|
||||
use const PHP_MINOR_VERSION;
|
||||
use const PHP_VERSION;
|
||||
|
||||
use function Amp\File\createDirectory;
|
||||
use function Amp\File\exists;
|
||||
use function Amp\File\getStatus;
|
||||
use function Amp\File\isDirectory;
|
||||
use function Amp\File\isFile;
|
||||
use function Amp\File\move;
|
||||
use function Amp\File\openFile;
|
||||
use function Amp\File\touch;
|
||||
@ -43,7 +47,7 @@ final class SessionPaths
|
||||
/**
|
||||
* Legacy session path.
|
||||
*/
|
||||
private string $legacySessionPath;
|
||||
private string $sessionDirectoryPath;
|
||||
/**
|
||||
* Session path.
|
||||
*/
|
||||
@ -81,13 +85,29 @@ final class SessionPaths
|
||||
public function __construct(string $session)
|
||||
{
|
||||
$session = Tools::absolute($session);
|
||||
$this->legacySessionPath = $session;
|
||||
$this->sessionPath = "$session.safe.php";
|
||||
$this->lightStatePath = "$session.lightState.php";
|
||||
$this->lockPath = "$session.lock";
|
||||
$this->ipcPath = "$session.ipc";
|
||||
$this->ipcCallbackPath = "$session.callback.ipc";
|
||||
$this->ipcStatePath = "$session.ipcState.php";
|
||||
$this->sessionDirectoryPath = $session;
|
||||
$this->sessionPath = "$session/safe.php";
|
||||
$this->lightStatePath = "$session/lightState.php";
|
||||
$this->lockPath = "$session/lock";
|
||||
$this->ipcPath = "$session/ipc";
|
||||
$this->ipcCallbackPath = "$session/callback.ipc";
|
||||
$this->ipcStatePath = "$session/ipcState.php";
|
||||
if (!exists($session)) {
|
||||
createDirectory($session);
|
||||
return;
|
||||
}
|
||||
if (!isDirectory($session) && isFile("$session.safe.php")) {
|
||||
\unlink($session);
|
||||
createDirectory($session);
|
||||
foreach (['safe.php', 'lightState.php', 'lock', 'ipc', 'callback.ipc', 'ipcState.php'] as $part) {
|
||||
if (exists("$session.$part")) {
|
||||
move("$session.$part", "$session/$part");
|
||||
}
|
||||
if (exists("$session.$part.lock")) {
|
||||
move("$session.$part.lock", "$session/$part.lock");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Serialize object to file.
|
||||
@ -166,15 +186,15 @@ final class SessionPaths
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->legacySessionPath;
|
||||
return $this->sessionDirectoryPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get legacy session path.
|
||||
*/
|
||||
public function getLegacySessionPath(): string
|
||||
public function getSessionDirectoryPath(): string
|
||||
{
|
||||
return $this->legacySessionPath;
|
||||
return $this->sessionDirectoryPath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,7 +78,7 @@ final class Button implements JsonSerializable, ArrayAccess
|
||||
$this->button = $button;
|
||||
$this->id = $message['id'];
|
||||
$this->API = $API;
|
||||
$this->session = $API->getWrapper()->getSession()->getLegacySessionPath();
|
||||
$this->session = $API->getWrapper()->getSession()->getSessionDirectoryPath();
|
||||
}
|
||||
/**
|
||||
* Sleep function.
|
||||
|
Loading…
x
Reference in New Issue
Block a user