(sftpfs_fix_filename): return pointer to GString instead of pointer to char.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-03-28 10:43:46 +03:00
parent b71f66dbbd
commit 6596185573
4 changed files with 47 additions and 56 deletions

View File

@ -82,14 +82,13 @@ sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror)
while (TRUE)
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
int libssh_errno;
fixfname = sftpfs_fix_filename (path_element->path, &fixfname_len);
fixfname = sftpfs_fix_filename (path_element->path);
handle =
libssh2_sftp_open_ex (sftpfs_super->sftp_session, fixfname, fixfname_len, 0, 0,
libssh2_sftp_open_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len, 0, 0,
LIBSSH2_SFTP_OPENDIR);
if (handle != NULL)
break;
@ -195,12 +194,12 @@ sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** mcerror)
do
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
fixfname = sftpfs_fix_filename (path_element->path, &fixfname_len);
fixfname = sftpfs_fix_filename (path_element->path);
res = libssh2_sftp_mkdir_ex (sftpfs_super->sftp_session, fixfname, fixfname_len, mode);
res =
libssh2_sftp_mkdir_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len, mode);
if (res >= 0)
break;
@ -245,12 +244,11 @@ sftpfs_rmdir (const vfs_path_t * vpath, GError ** mcerror)
do
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
fixfname = sftpfs_fix_filename (path_element->path, &fixfname_len);
fixfname = sftpfs_fix_filename (path_element->path);
res = libssh2_sftp_rmdir_ex (sftpfs_super->sftp_session, fixfname, fixfname_len);
res = libssh2_sftp_rmdir_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len);
if (res >= 0)
break;

View File

@ -158,15 +158,14 @@ sftpfs_open_file (vfs_file_handler_t * fh, int flags, mode_t mode, GError ** mce
while (TRUE)
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
int libssh_errno;
fixfname = sftpfs_fix_filename (name, &fixfname_len);
fixfname = sftpfs_fix_filename (name);
file->handle =
libssh2_sftp_open_ex (super->sftp_session, fixfname, fixfname_len, sftp_open_flags,
sftp_open_mode, LIBSSH2_SFTP_OPENFILE);
libssh2_sftp_open_ex (super->sftp_session, fixfname->str, fixfname->len,
sftp_open_flags, sftp_open_mode, LIBSSH2_SFTP_OPENFILE);
if (file->handle != NULL)
break;

View File

@ -149,12 +149,11 @@ sftpfs_stat_init (sftpfs_super_t ** super, const vfs_path_element_t ** path_elem
do
{
const char *fixfname;
unsigned int fixfname_len;
const GString *fixfname;
fixfname = sftpfs_fix_filename ((*path_element)->path, &fixfname_len);
fixfname = sftpfs_fix_filename ((*path_element)->path);
res = libssh2_sftp_stat_ex ((*super)->sftp_session, fixfname, fixfname_len,
res = libssh2_sftp_stat_ex ((*super)->sftp_session, fixfname->str, fixfname->len,
stat_type, attrs);
if (res >= 0)
break;
@ -236,12 +235,11 @@ sftpfs_ssherror_to_gliberror (sftpfs_super_t * super, int libssh_errno, GError *
* @return pointer to string that contains the file name with leading slash
*/
const char *
sftpfs_fix_filename (const char *file_name, unsigned int *length)
const GString *
sftpfs_fix_filename (const char *file_name)
{
g_string_printf (sftpfs_filename_buffer, "%c%s", PATH_SEP, file_name);
*length = sftpfs_filename_buffer->len;
return sftpfs_filename_buffer->str;
return sftpfs_filename_buffer;
}
/* --------------------------------------------------------------------------------------------- */
@ -355,13 +353,12 @@ sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** mce
do
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
fixfname = sftpfs_fix_filename (path_element->path, &fixfname_len);
fixfname = sftpfs_fix_filename (path_element->path);
res =
libssh2_sftp_symlink_ex (super->sftp_session, fixfname, fixfname_len, buf, size,
libssh2_sftp_symlink_ex (super->sftp_session, fixfname->str, fixfname->len, buf, size,
LIBSSH2_SFTP_READLINK);
if (res >= 0)
break;
@ -390,7 +387,7 @@ sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError **
sftpfs_super_t *super = NULL;
const vfs_path_element_t *path_element1;
const vfs_path_element_t *path_element2 = NULL;
const char *ctmp_path;
const GString *ctmp_path;
char *tmp_path;
unsigned int tmp_path_len;
int res;
@ -398,20 +395,20 @@ sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError **
if (!sftpfs_op_init (&super, &path_element2, vpath2, mcerror))
return -1;
ctmp_path = sftpfs_fix_filename (path_element2->path, &tmp_path_len);
tmp_path = g_strndup (ctmp_path, tmp_path_len);
ctmp_path = sftpfs_fix_filename (path_element2->path);
tmp_path = g_strndup (ctmp_path->str, ctmp_path->len);
tmp_path_len = ctmp_path->len;
path_element1 = vfs_path_get_by_index (vpath1, -1);
do
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
fixfname = sftpfs_fix_filename (path_element1->path, &fixfname_len);
fixfname = sftpfs_fix_filename (path_element1->path);
res =
libssh2_sftp_symlink_ex (super->sftp_session, fixfname, fixfname_len, tmp_path,
libssh2_sftp_symlink_ex (super->sftp_session, fixfname->str, fixfname->len, tmp_path,
tmp_path_len, LIBSSH2_SFTP_SYMLINK);
if (res >= 0)
break;
@ -456,13 +453,12 @@ sftpfs_utime (const vfs_path_t * vpath, time_t atime, time_t mtime, GError ** mc
do
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
fixfname = sftpfs_fix_filename (path_element->path, &fixfname_len);
fixfname = sftpfs_fix_filename (path_element->path);
res =
libssh2_sftp_stat_ex (super->sftp_session, fixfname, fixfname_len,
libssh2_sftp_stat_ex (super->sftp_session, fixfname->str, fixfname->len,
LIBSSH2_SFTP_SETSTAT, &attrs);
if (res >= 0)
break;
@ -510,13 +506,12 @@ sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror)
do
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
fixfname = sftpfs_fix_filename (path_element->path, &fixfname_len);
fixfname = sftpfs_fix_filename (path_element->path);
res =
libssh2_sftp_stat_ex (super->sftp_session, fixfname, fixfname_len,
libssh2_sftp_stat_ex (super->sftp_session, fixfname->str, fixfname->len,
LIBSSH2_SFTP_SETSTAT, &attrs);
if (res >= 0)
break;
@ -559,12 +554,11 @@ sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror)
do
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
fixfname = sftpfs_fix_filename (path_element->path, &fixfname_len);
fixfname = sftpfs_fix_filename (path_element->path);
res = libssh2_sftp_unlink_ex (super->sftp_session, fixfname, fixfname_len);
res = libssh2_sftp_unlink_ex (super->sftp_session, fixfname->str, fixfname->len);
if (res >= 0)
break;
@ -592,7 +586,7 @@ sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** m
sftpfs_super_t *super = NULL;
const vfs_path_element_t *path_element1;
const vfs_path_element_t *path_element2 = NULL;
const char *ctmp_path;
const GString *ctmp_path;
char *tmp_path;
unsigned int tmp_path_len;
int res;
@ -600,20 +594,20 @@ sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** m
if (!sftpfs_op_init (&super, &path_element2, vpath2, mcerror))
return -1;
ctmp_path = sftpfs_fix_filename (path_element2->path, &tmp_path_len);
tmp_path = g_strndup (ctmp_path, tmp_path_len);
ctmp_path = sftpfs_fix_filename (path_element2->path);
tmp_path = g_strndup (ctmp_path->str, ctmp_path->len);
tmp_path_len = ctmp_path->len;
path_element1 = vfs_path_get_by_index (vpath1, -1);
do
{
const char *fixfname;
unsigned int fixfname_len = 0;
const GString *fixfname;
fixfname = sftpfs_fix_filename (path_element1->path, &fixfname_len);
fixfname = sftpfs_fix_filename (path_element1->path);
res =
libssh2_sftp_rename_ex (super->sftp_session, fixfname, fixfname_len, tmp_path,
libssh2_sftp_rename_ex (super->sftp_session, fixfname->str, fixfname->len, tmp_path,
tmp_path_len, LIBSSH2_SFTP_SYMLINK);
if (res >= 0)
break;

View File

@ -72,7 +72,7 @@ gboolean sftpfs_is_sftp_error (LIBSSH2_SFTP * sftp_session, int sftp_res, int sf
void sftpfs_ssherror_to_gliberror (sftpfs_super_t * super, int libssh_errno, GError ** mcerror);
gboolean sftpfs_waitsocket (sftpfs_super_t * super, int sftp_res, GError ** mcerror);
const char *sftpfs_fix_filename (const char *file_name, unsigned int *length);
const GString *sftpfs_fix_filename (const char *file_name);
void sftpfs_attr_to_stat (const LIBSSH2_SFTP_ATTRIBUTES * attrs, struct stat *s);
int sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror);
int sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror);