SFTP: refactoring.

Re-order open_connection and reverse re-order close_connection steps.

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andreas Mohr 2016-01-03 17:36:34 +00:00 committed by Andrew Borodin
parent ece1d020fa
commit e740c7d3e5

View File

@ -371,11 +371,6 @@ sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror)
super_data = (sftpfs_super_data_t *) super->data;
/* Create a session instance */
super_data->session = libssh2_session_init ();
if (super_data->session == NULL)
return (-1);
/*
* The application code is responsible for creating the socket
* and establishing the connection
@ -384,6 +379,11 @@ sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror)
if (super_data->socket_handle == -1)
return (-1);
/* Create a session instance */
super_data->session = libssh2_session_init ();
if (super_data->session == NULL)
return (-1);
/* ... start it up. This will trade welcome banners, exchange keys,
* and setup crypto, compression, and MAC layers
*/
@ -440,6 +440,12 @@ sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message
if (super_data == NULL)
return;
if (super_data->sftp_session != NULL)
{
libssh2_sftp_shutdown (super_data->sftp_session);
super_data->sftp_session = NULL;
}
if (super_data->agent != NULL)
{
libssh2_agent_disconnect (super_data->agent);
@ -447,11 +453,7 @@ sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message
super_data->agent = NULL;
}
if (super_data->sftp_session != NULL)
{
libssh2_sftp_shutdown (super_data->sftp_session);
super_data->sftp_session = NULL;
}
super_data->fingerprint = NULL;
if (super_data->session != NULL)
{
@ -460,8 +462,6 @@ sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message
super_data->session = NULL;
}
super_data->fingerprint = NULL;
if (super_data->socket_handle != -1)
{
close (super_data->socket_handle);