Fix unlinkSessionFile method

This commit is contained in:
Alexander Pankratov 2021-01-13 23:51:08 +03:00
parent cebb56ee28
commit 7c833ba904

View File

@ -2,6 +2,7 @@
namespace TelegramApiServer\MadelineProtoExtensions; namespace TelegramApiServer\MadelineProtoExtensions;
use Amp\Loop;
use Amp\Promise; use Amp\Promise;
use danog\MadelineProto; use danog\MadelineProto;
use danog\MadelineProto\MTProto; use danog\MadelineProto\MTProto;
@ -100,11 +101,16 @@ class SystemApiExtensions
$file = Files::getSessionFile($session); $file = Files::getSessionFile($session);
if (is_file($file)) { if (is_file($file)) {
yield \Amp\File\unlink($file); $promises = [];
yield \Amp\File\unlink($file . '.lock'); foreach (glob("$file*") as $file) {
$promises[] = \Amp\File\unlink($file);
}
yield from $promises;
} else {
throw new \InvalidArgumentException('Session file not found');
} }
yield from $this->unlinkSessionSettings($session); yield $this->unlinkSessionSettings($session);
return 'ok'; return 'ok';
}); });
@ -129,6 +135,11 @@ class SystemApiExtensions
}); });
} }
public function exit(): string {
Loop::defer(static fn() => exit());
return 'ok';
}
private function bytesToHuman($bytes): string private function bytesToHuman($bytes): string
{ {
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];