sftpfs: refactoring: move handling of socket errors to separate function.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
xenogenesi 2017-01-15 16:11:31 +03:00 committed by Andrew Borodin
parent 29b9c1d81d
commit d5f6f317b2

View File

@ -66,6 +66,30 @@ sftpfs_blksize (struct stat *s)
vfs_adjust_stat (s);
}
/* --------------------------------------------------------------------------------------------- */
static gboolean
sftpfs_waitsocket_or_error (sftpfs_super_data_t * super_data, int res, GError ** mcerror,
void *to_free)
{
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
g_free (to_free);
return FALSE;
}
sftpfs_waitsocket (super_data, mcerror);
if (mcerror != NULL && *mcerror != NULL)
{
g_free (to_free);
return FALSE;
}
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
@ -232,15 +256,9 @@ sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror)
if (sftpfs_is_sftp_error (super_data->sftp_session, res, LIBSSH2_FX_NO_SUCH_FILE))
return -ENOENT;
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);
sftpfs_attr_to_stat (&attrs, buf);
@ -302,15 +320,9 @@ sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror)
if (sftpfs_is_sftp_error (super_data->sftp_session, res, LIBSSH2_FX_NO_SUCH_FILE))
return -ENOENT;
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);
buf->st_nlink = 1;
@ -366,15 +378,9 @@ sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** mce
if (res >= 0)
break;
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);
return res;
@ -433,20 +439,9 @@ sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError **
if (res >= 0)
break;
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
g_free (tmp_path);
if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, tmp_path))
return -1;
}
sftpfs_waitsocket (super_data, mcerror);
if (mcerror != NULL && *mcerror != NULL)
{
g_free (tmp_path);
return -1;
}
}
while (res == LIBSSH2_ERROR_EAGAIN);
g_free (tmp_path);
@ -508,15 +503,9 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror)
break;
}
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);
attrs.permissions = mode;
@ -543,15 +532,9 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror)
break;
}
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);
return res;
@ -599,15 +582,9 @@ sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror)
if (res >= 0)
break;
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
}
while (res == LIBSSH2_ERROR_EAGAIN);
return res;
@ -665,20 +642,9 @@ sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** m
if (res >= 0)
break;
if (res != LIBSSH2_ERROR_EAGAIN)
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
g_free (tmp_path);
if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, tmp_path))
return -1;
}
sftpfs_waitsocket (super_data, mcerror);
if (mcerror != NULL && *mcerror != NULL)
{
g_free (tmp_path);
return -1;
}
}
while (res == LIBSSH2_ERROR_EAGAIN);
g_free (tmp_path);