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); 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 ****************************************************************************/ /*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -232,14 +256,8 @@ 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)) if (sftpfs_is_sftp_error (super_data->sftp_session, res, LIBSSH2_FX_NO_SUCH_FILE))
return -ENOENT; return -ENOENT;
if (res != LIBSSH2_ERROR_EAGAIN) if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -302,14 +320,8 @@ 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)) if (sftpfs_is_sftp_error (super_data->sftp_session, res, LIBSSH2_FX_NO_SUCH_FILE))
return -ENOENT; return -ENOENT;
if (res != LIBSSH2_ERROR_EAGAIN) if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -366,14 +378,8 @@ sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** mce
if (res >= 0) if (res >= 0)
break; break;
if (res != LIBSSH2_ERROR_EAGAIN) if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -433,19 +439,8 @@ sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError **
if (res >= 0) if (res >= 0)
break; break;
if (res != LIBSSH2_ERROR_EAGAIN) if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, tmp_path))
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
g_free (tmp_path);
return -1; return -1;
}
sftpfs_waitsocket (super_data, mcerror);
if (mcerror != NULL && *mcerror != NULL)
{
g_free (tmp_path);
return -1;
}
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
g_free (tmp_path); g_free (tmp_path);
@ -508,14 +503,8 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror)
break; break;
} }
if (res != LIBSSH2_ERROR_EAGAIN) if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -543,14 +532,8 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror)
break; break;
} }
if (res != LIBSSH2_ERROR_EAGAIN) if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -599,14 +582,8 @@ sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror)
if (res >= 0) if (res >= 0)
break; break;
if (res != LIBSSH2_ERROR_EAGAIN) if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, NULL))
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
return -1; return -1;
}
sftpfs_waitsocket (super_data, mcerror);
mc_return_val_if_error (mcerror, -1);
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
@ -665,19 +642,8 @@ sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** m
if (res >= 0) if (res >= 0)
break; break;
if (res != LIBSSH2_ERROR_EAGAIN) if (!sftpfs_waitsocket_or_error (super_data, res, mcerror, tmp_path))
{
sftpfs_ssherror_to_gliberror (super_data, res, mcerror);
g_free (tmp_path);
return -1; return -1;
}
sftpfs_waitsocket (super_data, mcerror);
if (mcerror != NULL && *mcerror != NULL)
{
g_free (tmp_path);
return -1;
}
} }
while (res == LIBSSH2_ERROR_EAGAIN); while (res == LIBSSH2_ERROR_EAGAIN);
g_free (tmp_path); g_free (tmp_path);