From d5f6f317b2588705fec2f1d253354cfd59bfaf90 Mon Sep 17 00:00:00 2001 From: xenogenesi Date: Sun, 15 Jan 2017 16:11:31 +0300 Subject: [PATCH] sftpfs: refactoring: move handling of socket errors to separate function. Signed-off-by: Andrew Borodin --- src/vfs/sftpfs/internal.c | 98 +++++++++++++-------------------------- 1 file changed, 32 insertions(+), 66 deletions(-) diff --git a/src/vfs/sftpfs/internal.c b/src/vfs/sftpfs/internal.c index 571e81081..664729835 100644 --- a/src/vfs/sftpfs/internal.c +++ b/src/vfs/sftpfs/internal.c @@ -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,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)) 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); @@ -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)) 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); @@ -366,14 +378,8 @@ 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); @@ -433,19 +439,8 @@ 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,14 +503,8 @@ 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); @@ -543,14 +532,8 @@ 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); @@ -599,14 +582,8 @@ 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); @@ -665,19 +642,8 @@ 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);