Browse Source

Following prototypes of functions was changed in VFS-module API:

 * getid
 * mkdir
 * rmdir
 * setctl

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Slava Zanko 14 years ago
parent
commit
152124d9b7
10 changed files with 143 additions and 89 deletions
  1. 20 16
      lib/vfs/direntry.c
  2. 28 21
      lib/vfs/gc.c
  3. 0 1
      lib/vfs/gc.h
  4. 9 6
      lib/vfs/interface.c
  5. 5 5
      lib/vfs/vfs.h
  6. 8 6
      src/filemanager/midnight.c
  7. 18 13
      src/vfs/extfs/extfs.c
  8. 42 9
      src/vfs/fish/fish.c
  9. 9 4
      src/vfs/ftpfs/ftpfs.c
  10. 4 8
      src/vfs/local/local.c

+ 20 - 16
lib/vfs/direntry.c

@@ -818,13 +818,17 @@ vfs_s_ungetlocalcopy (const vfs_path_t * vpath, const char *local, int has_chang
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-vfs_s_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
+vfs_s_setctl (const vfs_path_t * vpath, int ctlop, void *arg)
 {
+    vfs_path_element_t *path_element;
+
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
     switch (ctlop)
     {
     case VFS_SETCTL_STALE_DATA:
         {
-            struct vfs_s_inode *ino = vfs_s_inode_from_path (me, path, 0);
+            struct vfs_s_inode *ino =
+                vfs_s_inode_from_path (path_element->class, vpath->unparsed, 0);
 
             if (ino == NULL)
                 return 0;
@@ -833,15 +837,15 @@ vfs_s_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
             else
             {
                 ino->super->want_stale = 0;
-                vfs_s_invalidate (me, ino->super);
+                vfs_s_invalidate (path_element->class, ino->super);
             }
             return 1;
         }
     case VFS_SETCTL_LOGFILE:
-        MEDATA->logfile = fopen ((char *) arg, "w");
+        ((struct vfs_s_subclass *) path_element->class->data)->logfile = fopen ((char *) arg, "w");
         return 1;
     case VFS_SETCTL_FLUSH:
-        MEDATA->flush = 1;
+        ((struct vfs_s_subclass *) path_element->class->data)->flush = 1;
         return 1;
     }
     return 0;
@@ -851,12 +855,15 @@ vfs_s_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
 /* ----------------------------- Stamping support -------------------------- */
 
 static vfsid
-vfs_s_getid (struct vfs_class *me, const char *path)
+vfs_s_getid (const vfs_path_t * vpath)
 {
     struct vfs_s_super *archive = NULL;
     char *p;
+    vfs_path_element_t *path_element;
 
-    p = vfs_s_get_path (me, path, &archive, FL_NO_OPEN);
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
+
+    p = vfs_s_get_path (path_element->class, vpath->unparsed, &archive, FL_NO_OPEN);
     if (p == NULL)
         return NULL;
     g_free (p);
@@ -1380,18 +1387,15 @@ vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub)
 /** Find VFS id for given directory name */
 
 vfsid
-vfs_getid (struct vfs_class *vclass, const char *dir)
+vfs_getid (const vfs_path_t * vpath)
 {
-    char *dir1;
-    vfsid id = NULL;
+    vfs_path_element_t *path_element;
 
-    /* append slash if needed */
-    dir1 = concat_dir_and_file (dir, "");
-    if (vclass->getid)
-        id = (*vclass->getid) (vclass, dir1);
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
+    if (path_element == NULL || path_element->class->getid == NULL)
+        return NULL;
 
-    g_free (dir1);
-    return id;
+    return (*path_element->class->getid) (vpath);
 }
 
 /* --------------------------------------------------------------------------------------------- */

+ 28 - 21
lib/vfs/gc.c

@@ -153,12 +153,16 @@ vfs_rmstamp (struct vfs_class *v, vfsid id)
 void
 vfs_stamp_path (const char *path)
 {
-    struct vfs_class *vfs;
     vfsid id;
+    vfs_path_t *vpath;
+    vfs_path_element_t *path_element;
 
-    vfs = vfs_get_class (path);
-    id = vfs_getid (vfs, path);
-    vfs_addstamp (vfs, id);
+    vpath = vfs_path_from_str (path);
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
+
+    id = vfs_getid (vpath);
+    vfs_addstamp (path_element->class, id);
+    vfs_path_free (vpath);
 }
 
 /* --------------------------------------------------------------------------------------------- */
@@ -169,10 +173,11 @@ vfs_stamp_path (const char *path)
 void
 vfs_stamp_create (struct vfs_class *vclass, vfsid id)
 {
-    struct vfs_class *nvfs;
     vfsid nvfsid;
 
     ev_vfs_stamp_create_t event_data = { vclass, id, FALSE };
+    vfs_path_t *vpath;
+    vfs_path_element_t *path_element;
 
     /* There are three directories we have to take care of: current_dir,
        current_panel->cwd and other_panel->cwd. Athough most of the time either
@@ -182,20 +187,21 @@ vfs_stamp_create (struct vfs_class *vclass, vfsid id)
     if (!mc_event_present (MCEVENT_GROUP_CORE, "vfs_timestamp"))
         return;
 
-    nvfs = vfs_get_class (vfs_get_current_dir ());
-    nvfsid = vfs_getid (nvfs, vfs_get_current_dir ());
-    vfs_rmstamp (nvfs, nvfsid);
-
-    if (id == NULL || (nvfs == vclass && nvfsid == id))
-        return;
+    vpath = vfs_path_from_str (vfs_get_current_dir ());
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
 
-    mc_event_raise (MCEVENT_GROUP_CORE, "vfs_timestamp", (gpointer) &event_data);
+    nvfsid = vfs_getid (vpath);
+    vfs_rmstamp (path_element->class, nvfsid);
 
-    if (event_data.ret)
-        return;
+    if (!(id == NULL || (path_element->class == vclass && nvfsid == id)))
+    {
+        mc_event_raise (MCEVENT_GROUP_CORE, "vfs_timestamp", (gpointer) & event_data);
 
-    if (vclass != NULL && vclass->nothingisopen != NULL && vclass->nothingisopen (id) != 0)
-        vfs_addstamp (vclass, id);
+        if (!event_data.ret && vclass != NULL && vclass->nothingisopen != NULL
+            && vclass->nothingisopen (id) != 0)
+            vfs_addstamp (vclass, id);
+    }
+    vfs_path_free (vpath);
 }
 
 /* --------------------------------------------------------------------------------------------- */
@@ -260,12 +266,13 @@ vfs_timeout_handler (void)
 void
 vfs_release_path (const char *dir)
 {
-    struct vfs_class *oldvfs;
-    vfsid oldvfsid;
+    vfs_path_t *vpath;
+    vfs_path_element_t *path_element;
+
+    vpath = vfs_path_from_str (dir);
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
 
-    oldvfs = vfs_get_class (dir);
-    oldvfsid = vfs_getid (oldvfs, dir);
-    vfs_stamp_create (oldvfs, oldvfsid);
+    vfs_stamp_create (path_element->class, vfs_getid (vpath));
 }
 
 /* --------------------------------------------------------------------------------------------- */

+ 0 - 1
lib/vfs/gc.h

@@ -29,7 +29,6 @@ struct vfs_stamping
 void vfs_stamp (struct vfs_class *vclass, vfsid id);
 void vfs_rmstamp (struct vfs_class *vclass, vfsid id);
 void vfs_stamp_create (struct vfs_class *vclass, vfsid id);
-vfsid vfs_getid (struct vfs_class *vclass, const char *dir);
 void vfs_gc_done (void);
 
 /*** inline functions ****************************************************************************/

+ 9 - 6
lib/vfs/interface.c

@@ -260,8 +260,8 @@ MC_NAMEOP (chown, (const char *path, uid_t owner, gid_t group), (vpath, owner, g
 MC_NAMEOP (utime, (const char *path, struct utimbuf * times), (vpath, times))
 MC_NAMEOP (readlink, (const char *path, char *buf, size_t bufsiz), (vpath, buf, bufsiz))
 MC_NAMEOP (unlink, (const char *path), (vpath))
-MC_NAMEOP (mkdir, (const char *path, mode_t mode), (path_element->class, vpath->unparsed, mode))
-MC_NAMEOP (rmdir, (const char *path), (path_element->class, vpath->unparsed))
+MC_NAMEOP (mkdir, (const char *path, mode_t mode), (vpath, mode))
+MC_NAMEOP (rmdir, (const char *path), (vpath))
 MC_NAMEOP (mknod, (const char *path, mode_t mode, dev_t dev), (vpath, mode, dev))
 
 /* *INDENT-ON* */
@@ -399,8 +399,7 @@ mc_setctl (const char *path, int ctlop, void *arg)
     path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
     if (path_element != NULL && path_element->class != NULL)
         result =
-            path_element->class->setctl != NULL ? path_element->class->setctl (path_element->class,
-                                                                               vpath->unparsed,
+            path_element->class->setctl != NULL ? path_element->class->setctl (vpath,
                                                                                ctlop, arg) : 0;
 
     vfs_path_free (vpath);
@@ -729,8 +728,12 @@ mc_chdir (const char *path)
         return -1;
     }
 
-    old_vfsid = vfs_getid (current_vfs, current_dir);
-    old_vfs = current_vfs;
+    {
+        vfs_path_t *current_vpath = vfs_path_from_str (current_dir);
+        old_vfsid = vfs_getid (current_vpath);
+        old_vfs = current_vfs;
+        vfs_path_free (current_vpath);
+    }
 
     /* Actually change directory */
     g_free (current_dir);

+ 5 - 5
lib/vfs/vfs.h

@@ -178,7 +178,7 @@ typedef struct vfs_class
       off_t (*lseek) (void *vfs_info, off_t offset, int whence);
     int (*mknod) (const vfs_path_t * vpath, mode_t mode, dev_t dev);
 
-      vfsid (*getid) (struct vfs_class * me, const char *path);
+      vfsid (*getid) (const vfs_path_t * vpath);
 
     int (*nothingisopen) (vfsid id);
     void (*free) (vfsid id);
@@ -186,11 +186,11 @@ typedef struct vfs_class
     char *(*getlocalcopy) (const vfs_path_t * vpath);
     int (*ungetlocalcopy) (const vfs_path_t * vpath, const char *local, int has_changed);
 
-    int (*mkdir) (struct vfs_class * me, const char *path, mode_t mode);
-    int (*rmdir) (struct vfs_class * me, const char *path);
+    int (*mkdir) (const vfs_path_t * vpath, mode_t mode);
+    int (*rmdir) (const vfs_path_t * vpath);
 
     int (*ctl) (void *vfs_info, int ctlop, void *arg);
-    int (*setctl) (struct vfs_class * me, const char *path, int ctlop, void *arg);
+    int (*setctl) (const vfs_path_t * vpath, int ctlop, void *arg);
 } vfs_class;
 
 /*
@@ -216,7 +216,7 @@ extern int use_netrc;
 /* lib/vfs/direntry.c: */
 void *vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode);
 
-vfsid vfs_getid (struct vfs_class *vclass, const char *dir);
+vfsid vfs_getid (const vfs_path_t * vpath);
 
 void vfs_init (void);
 void vfs_shut (void);

+ 8 - 6
src/filemanager/midnight.c

@@ -491,14 +491,16 @@ check_panel_timestamp (const WPanel * panel, panel_view_mode_t mode, struct vfs_
 {
     if (mode == view_listing)
     {
-        struct vfs_class *nvfs;
-        vfsid nvfsid;
+        vfs_path_t *vpath;
+        vfs_path_element_t *path_element;
 
-        nvfs = vfs_get_class (panel->cwd);
-        if (nvfs != vclass)
+        vpath = vfs_path_from_str (panel->cwd);
+        path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
+
+        if (path_element->class != vclass)
             return FALSE;
-        nvfsid = vfs_getid (nvfs, panel->cwd);
-        if (nvfsid != id)
+
+        if (vfs_getid (vpath) != id)
             return FALSE;
     }
     return TRUE;

+ 18 - 13
src/vfs/extfs/extfs.c

@@ -1245,24 +1245,25 @@ extfs_unlink (const vfs_path_t * vpath)
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
+extfs_mkdir (const vfs_path_t * vpath, mode_t mode)
 {
     struct archive *archive;
     char *q, *mpath;
     struct entry *entry;
     int result = -1;
+    vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
 
     (void) mode;
 
-    mpath = g_strdup (path);
+    mpath = g_strdup (vpath->unparsed);
 
-    q = extfs_get_path_mangle (me, mpath, &archive, FALSE);
+    q = extfs_get_path_mangle (path_element->class, mpath, &archive, FALSE);
     if (q == NULL)
         goto cleanup;
     entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE);
     if (entry != NULL)
     {
-        me->verrno = EEXIST;
+        path_element->class->verrno = EEXIST;
         goto cleanup;
     }
     entry = extfs_find_entry (archive->root_entry, q, TRUE, FALSE);
@@ -1273,7 +1274,7 @@ extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
         goto cleanup;
     if (!S_ISDIR (entry->inode->mode))
     {
-        me->verrno = ENOTDIR;
+        path_element->class->verrno = ENOTDIR;
         goto cleanup;
     }
 
@@ -1292,16 +1293,17 @@ extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-extfs_rmdir (struct vfs_class *me, const char *path)
+extfs_rmdir (const vfs_path_t * vpath)
 {
     struct archive *archive;
     char *q, *mpath;
     struct entry *entry;
     int result = -1;
+    vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
 
-    mpath = g_strdup (path);
+    mpath = g_strdup (vpath->unparsed);
 
-    q = extfs_get_path_mangle (me, mpath, &archive, FALSE);
+    q = extfs_get_path_mangle (path_element->class, mpath, &archive, FALSE);
     if (q == NULL)
         goto cleanup;
     entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE);
@@ -1312,7 +1314,7 @@ extfs_rmdir (struct vfs_class *me, const char *path)
         goto cleanup;
     if (!S_ISDIR (entry->inode->mode))
     {
-        me->verrno = ENOTDIR;
+        path_element->class->verrno = ENOTDIR;
         goto cleanup;
     }
 
@@ -1366,12 +1368,13 @@ extfs_lseek (void *data, off_t offset, int whence)
 /* --------------------------------------------------------------------------------------------- */
 
 static vfsid
-extfs_getid (struct vfs_class *me, const char *path)
+extfs_getid (const vfs_path_t * vpath)
 {
     struct archive *archive = NULL;
     char *p;
+    vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
 
-    p = extfs_get_path (me, path, &archive, TRUE);
+    p = extfs_get_path (path_element->class, vpath->unparsed, &archive, TRUE);
     if (p == NULL)
         return NULL;
     g_free (p);
@@ -1683,13 +1686,15 @@ extfs_done (struct vfs_class *me)
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-extfs_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
+extfs_setctl (const vfs_path_t * vpath, int ctlop, void *arg)
 {
+    vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
+
     (void) arg;
 
     if (ctlop == VFS_SETCTL_RUN)
     {
-        extfs_run (me, path);
+        extfs_run (path_element->class, vpath->unparsed);
         return 1;
     }
     return 0;

+ 42 - 9
src/vfs/fish/fish.c

@@ -1403,46 +1403,79 @@ fish_exists (struct vfs_class *me, const char *path)
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-fish_mkdir (struct vfs_class *me, const char *path, mode_t mode)
+fish_mkdir (const vfs_path_t * vpath, mode_t mode)
 {
     gchar *shell_commands = NULL;
     int ret_code;
-
-    PREFIX;
+    char buf[BUF_LARGE];
+    const char *crpath;
+    char *rpath, *mpath;
+    struct vfs_s_super *super;
+    vfs_path_element_t *path_element;
 
     (void) mode;
 
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
+
+    mpath = g_strdup (vpath->unparsed);
+    crpath = vfs_s_get_path_mangle (path_element->class, mpath, &super, 0);
+    if (crpath == NULL)
+    {
+        g_free (mpath);
+        return -1;
+    }
+    rpath = strutils_shell_escape (crpath);
+    g_free (mpath);
+
     shell_commands =
         g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_mkdir, (char *) NULL);
     g_snprintf (buf, sizeof (buf), shell_commands, rpath);
     g_free (shell_commands);
 
     g_free (rpath);
-    ret_code = fish_send_command (me, super, buf, OPT_FLUSH);
+    ret_code = fish_send_command (path_element->class, super, buf, OPT_FLUSH);
 
     if (ret_code != 0)
         return ret_code;
 
-    if (!fish_exists (me, path))
-        ERRNOR (EACCES, -1);
+    if (!fish_exists (path_element->class, vpath->unparsed))
+    {
+        path_element->class->verrno = EACCES;
+        return -1;
+    }
     return 0;
 }
 
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-fish_rmdir (struct vfs_class *me, const char *path)
+fish_rmdir (const vfs_path_t * vpath)
 {
     gchar *shell_commands = NULL;
+    char buf[BUF_LARGE];
+    const char *crpath;
+    char *rpath, *mpath;
+    struct vfs_s_super *super;
+    vfs_path_element_t *path_element;
 
-    PREFIX;
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
+
+    mpath = g_strdup (vpath->unparsed);
+    crpath = vfs_s_get_path_mangle (path_element->class, mpath, &super, 0);
+    if (crpath == NULL)
+    {
+        g_free (mpath);
+        return -1;
+    }
+    rpath = strutils_shell_escape (crpath);
+    g_free (mpath);
 
     shell_commands =
         g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_rmdir, (char *) NULL);
     g_snprintf (buf, sizeof (buf), shell_commands, rpath);
     g_free (shell_commands);
     g_free (rpath);
-    return fish_send_command (me, super, buf, OPT_FLUSH);
+    return fish_send_command (path_element->class, super, buf, OPT_FLUSH);
 }
 
 /* --------------------------------------------------------------------------------------------- */

+ 9 - 4
src/vfs/ftpfs/ftpfs.c

@@ -2076,19 +2076,24 @@ ftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-ftpfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
+ftpfs_mkdir (const vfs_path_t * vpath, mode_t mode)
 {
+    vfs_path_element_t *path_element;
     (void) mode;                /* FIXME: should be used */
 
-    return ftpfs_send_command (me, path, "MKD /%s", OPT_FLUSH);
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
+    return ftpfs_send_command (path_element->class, vpath->unparsed, "MKD /%s", OPT_FLUSH);
 }
 
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-ftpfs_rmdir (struct vfs_class *me, const char *path)
+ftpfs_rmdir (const vfs_path_t * vpath)
 {
-    return ftpfs_send_command (me, path, "RMD /%s", OPT_FLUSH);
+    vfs_path_element_t *path_element;
+
+    path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
+    return ftpfs_send_command (path_element->class, vpath->unparsed, "RMD /%s", OPT_FLUSH);
 }
 
 /* --------------------------------------------------------------------------------------------- */

+ 4 - 8
src/vfs/local/local.c

@@ -242,21 +242,17 @@ local_link (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-local_mkdir (struct vfs_class *me, const char *path, mode_t mode)
+local_mkdir (const vfs_path_t * vpath, mode_t mode)
 {
-    (void) me;
-
-    return mkdir (path, mode);
+    return mkdir (vpath->unparsed, mode);
 }
 
 /* --------------------------------------------------------------------------------------------- */
 
 static int
-local_rmdir (struct vfs_class *me, const char *path)
+local_rmdir (const vfs_path_t * vpath)
 {
-    (void) me;
-
-    return rmdir (path);
+    return rmdir (vpath->unparsed);
 }
 
 /* --------------------------------------------------------------------------------------------- */

Some files were not shown because too many files changed in this diff