AcmeClient: Fixed not detecting remote side closing connection.

This commit is contained in:
Jürgen Kellerer
2019-08-17 23:19:23 +02:00
parent 68e7d29368
commit b54007176c
3 changed files with 10 additions and 6 deletions
@@ -62,7 +62,7 @@ class SftpClient
public function connected(): ?array
{
return $this->process
return $this->process && $this->process->isRunning()
? $this->connection_info
: null;
}
@@ -109,7 +109,7 @@ class SftpClient
// Creating the sftp process
if ($this->process = Process::open($cmd)) {
$this->processAvailableInput(self::CONNECT_REPLY_TIMEOUT, 1, null, 0.75);
if ($error = $this->lastError()) {
if (($error = $this->lastError()) || !$this->process->isRunning()) {
Utils::log()->error("Failed connecting to '$host' (user: '$username')", $error);
return false;
}
@@ -140,9 +140,6 @@ class SftpUploader
*/
public function upload(): int
{
$connection = Utils::requireThat($this->sftp->connected(), "The sftp client must be connected");
$username = $connection["user"];
// Correct state when we are restarted after an error
if ($this->current_file) {
// Restore the remote path to where we originally have been.
@@ -182,6 +179,12 @@ class SftpUploader
$this->sftp->clearError();
try {
$connection = $this->sftp->connected();
if (!$connection) {
Utils::log()->error("The sftp client is not connected, upload stopped.");
return self::UPLOAD_ERROR;
}
// Changing remote directory if required.
if (($target_dir = dirname($file["target"])) !== $remote_path) {
@@ -229,6 +232,7 @@ class SftpUploader
}
// Preparing upload
$username = $connection["user"];
$remote_filename = basename((empty($file["target"]) ? $local_file : $file["target"]));
$remote_file = $remote_files[$remote_filename] ?: ["type" => "-", "owner" => $username];
$remote_is_file = $remote_file["type"] === "-";
@@ -179,7 +179,7 @@ function commandTestConnection(array &$options): int
$result["actions"][] = "connected";
$result["remote"] = array_merge($sftp->connected(), ["path" => $sftp->pwd()]);
} else {
$result = array_merge($result, $error);
$result = array_merge($result, ($error ?: []));
}
// Testing file upload