From ea4078e52e0b2a67831d36f9b78f950cadc2cbba Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 29 Jun 2011 21:52:01 +0400 Subject: [PATCH] Ticket #2361: VFS URI reimplementation Code cleanup: * (vfs_set_raw_current_dir): remove redundant check. * VFS: minor optimizations. * Fixed type of mode argument of vfs_class:chmod method. Signed-off-by: Andrew Borodin Signed-off-by: Slava Zanko --- lib/vfs/interface.c | 7 +++---- lib/vfs/path.c | 17 ++++------------- lib/vfs/path.h | 2 -- lib/vfs/vfs.c | 3 +-- lib/vfs/vfs.h | 2 +- src/vfs/extfs/extfs.c | 2 +- src/vfs/fish/fish.c | 4 ++-- src/vfs/ftpfs/ftpfs.c | 4 ++-- src/vfs/local/local.c | 2 +- src/vfs/sfs/sfs.c | 2 +- src/vfs/smbfs/smbfs.c | 4 ++-- 11 files changed, 18 insertions(+), 31 deletions(-) diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c index c939605e9..31b5702d7 100644 --- a/lib/vfs/interface.c +++ b/lib/vfs/interface.c @@ -269,8 +269,7 @@ mc_symlink (const char *name1, const char *path) if (vpath2 != NULL) { - vfs_path_element_t *path_element = - vfs_path_get_by_index (vpath1, vfs_path_elements_count (vpath1) - 1); + vfs_path_element_t *path_element = vfs_path_get_by_index (vpath1, -1); if (vfs_path_element_valid (path_element)) { result = @@ -330,8 +329,8 @@ int mc_##name (const char *fname1, const char *fname2) \ vfs_path_free(vpath1); \ return -1; \ }\ - path_element1 = vfs_path_get_by_index (vpath1, vfs_path_elements_count (vpath1) - 1); \ - path_element2 = vfs_path_get_by_index (vpath2, vfs_path_elements_count (vpath2) - 1); \ + path_element1 = vfs_path_get_by_index (vpath1, - 1); \ + path_element2 = vfs_path_get_by_index (vpath2, - 1); \ \ if (!vfs_path_element_valid (path_element1) || !vfs_path_element_valid (path_element2) || \ path_element1->class != path_element2->class) \ diff --git a/lib/vfs/path.c b/lib/vfs/path.c index 058e6fedd..9406ebf32 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -664,10 +664,7 @@ vfs_path_new (void) int vfs_path_elements_count (const vfs_path_t * vpath) { - if (vpath == NULL) - return 0; - - return (vpath->path != NULL) ? g_list_length (vpath->path) : 0; + return (vpath != NULL && vpath->path != NULL) ? g_list_length (vpath->path) : 0; } /* --------------------------------------------------------------------------------------------- */ @@ -683,19 +680,13 @@ vfs_path_elements_count (const vfs_path_t * vpath) vfs_path_element_t * vfs_path_get_by_index (const vfs_path_t * vpath, int element_index) { - vfs_path_element_t *element; - - if (vpath == NULL) - return NULL; - if (element_index < 0) - element_index = vfs_path_elements_count (vpath) + element_index; + element_index += vfs_path_elements_count (vpath); - element = g_list_nth_data (vpath->path, element_index); - if (element == NULL) + if (element_index < 0) vfs_die ("vfs_path_get_by_index: incorrect index!"); - return element; + return g_list_nth_data (vpath->path, element_index); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/vfs/path.h b/lib/vfs/path.h index cc294c4c9..980ab9869 100644 --- a/lib/vfs/path.h +++ b/lib/vfs/path.h @@ -33,8 +33,6 @@ typedef struct GIConv converter; DIR *info; } dir; - - struct vfs_s_super *current_super_block; } vfs_path_element_t; /*** global variables defined in .c file *********************************************************/ diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c index 1a02c7553..c2ae6af70 100644 --- a/lib/vfs/vfs.c +++ b/lib/vfs/vfs.c @@ -379,8 +379,7 @@ vfs_get_raw_current_dir (void) void vfs_set_raw_current_dir (const vfs_path_t * vpath) { - if (current_path != NULL) - vfs_path_free (current_path); + vfs_path_free (current_path); current_path = (vfs_path_t *) vpath; } diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h index db236a794..5319711f9 100644 --- a/lib/vfs/vfs.h +++ b/lib/vfs/vfs.h @@ -163,7 +163,7 @@ typedef struct vfs_class int (*lstat) (const vfs_path_t * vpath, struct stat * buf); int (*fstat) (void *vfs_info, struct stat * buf); - int (*chmod) (const vfs_path_t * vpath, int mode); + int (*chmod) (const vfs_path_t * vpath, mode_t mode); int (*chown) (const vfs_path_t * vpath, uid_t owner, gid_t group); int (*utime) (const vfs_path_t * vpath, struct utimbuf * times); diff --git a/src/vfs/extfs/extfs.c b/src/vfs/extfs/extfs.c index 62d5e47e2..0bc5e14a7 100644 --- a/src/vfs/extfs/extfs.c +++ b/src/vfs/extfs/extfs.c @@ -1177,7 +1177,7 @@ extfs_chown (const vfs_path_t * vpath, uid_t owner, gid_t group) /* --------------------------------------------------------------------------------------------- */ static int -extfs_chmod (const vfs_path_t * vpath, int mode) +extfs_chmod (const vfs_path_t * vpath, mode_t mode) { (void) vpath; (void) mode; diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c index 8dfe4bb9d..5666cbdbd 100644 --- a/src/vfs/fish/fish.c +++ b/src/vfs/fish/fish.c @@ -1244,7 +1244,7 @@ fish_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2) /* --------------------------------------------------------------------------------------------- */ static int -fish_chmod (const vfs_path_t * vpath, int mode) +fish_chmod (const vfs_path_t * vpath, mode_t mode) { gchar *shell_commands = NULL; char buf[BUF_LARGE]; @@ -1262,7 +1262,7 @@ fish_chmod (const vfs_path_t * vpath, int mode) shell_commands = g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILEMODE=%4.4o;\n", SUP->scr_chmod, (char *) NULL); - g_snprintf (buf, sizeof (buf), shell_commands, rpath, mode & 07777); + g_snprintf (buf, sizeof (buf), shell_commands, rpath, (int) (mode & 07777)); g_free (shell_commands); g_free (rpath); return fish_send_command (path_element->class, super, buf, OPT_FLUSH); diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index 618632367..b9b2ed190 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -1981,12 +1981,12 @@ ftpfs_send_command (const vfs_path_t * vpath, const char *cmd, int flags) /* --------------------------------------------------------------------------------------------- */ static int -ftpfs_chmod (const vfs_path_t * vpath, int mode) +ftpfs_chmod (const vfs_path_t * vpath, mode_t mode) { char buf[BUF_SMALL]; int ret; - g_snprintf (buf, sizeof (buf), "SITE CHMOD %4.4o /%%s", mode & 07777); + g_snprintf (buf, sizeof (buf), "SITE CHMOD %4.4o /%%s", (int) (mode & 07777)); ret = ftpfs_send_command (vpath, buf, OPT_FLUSH); diff --git a/src/vfs/local/local.c b/src/vfs/local/local.c index 23c23313e..624e31258 100644 --- a/src/vfs/local/local.c +++ b/src/vfs/local/local.c @@ -141,7 +141,7 @@ local_lstat (const vfs_path_t * vpath, struct stat *buf) /* --------------------------------------------------------------------------------------------- */ static int -local_chmod (const vfs_path_t * vpath, int mode) +local_chmod (const vfs_path_t * vpath, mode_t mode) { vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1); diff --git a/src/vfs/sfs/sfs.c b/src/vfs/sfs/sfs.c index 24a85ae50..9055abe67 100644 --- a/src/vfs/sfs/sfs.c +++ b/src/vfs/sfs/sfs.c @@ -293,7 +293,7 @@ sfs_lstat (const vfs_path_t * vpath, struct stat *buf) /* --------------------------------------------------------------------------------------------- */ static int -sfs_chmod (const vfs_path_t * vpath, int mode) +sfs_chmod (const vfs_path_t * vpath, mode_t mode) { return chmod (sfs_redirect (vpath), mode); } diff --git a/src/vfs/smbfs/smbfs.c b/src/vfs/smbfs/smbfs.c index 3e0589b43..c9c86dfec 100644 --- a/src/vfs/smbfs/smbfs.c +++ b/src/vfs/smbfs/smbfs.c @@ -964,11 +964,11 @@ smbfs_closedir (void *info) /* --------------------------------------------------------------------------------------------- */ static int -smbfs_chmod (const vfs_path_t * vpath, int mode) +smbfs_chmod (const vfs_path_t * vpath, mode_t mode) { vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1); - DEBUG (3, ("smbfs_chmod(path:%s, mode:%d)\n", path_element->path, mode)); + DEBUG (3, ("smbfs_chmod(path:%s, mode:%d)\n", path_element->path, (int) mode)); /* my_errno = EOPNOTSUPP; return -1; *//* cannot chmod on smb filesystem */ return 0; /* make mc happy */ -- 2.11.4.GIT