Browse Source

Merge branch '3955_cleanup'

* 3955_cleanup:
  Update po/*.po files.
  src/vfs/extfs/helpers/Makefile.am: clarify condition.
  VFS: move src/vfs/extfs/helpers/sfs.ini to src/vfs/sfs.
  src/vfs/sfs/sfs.c: refactor flags and options.
  (sfs_init): refactor loop.
  (sfs_vfmake): use gboolean instead of int for boolean variable was_percent.
  src/vfs/sfs/sfs.c: fix coding style.
  src/vfs/local/local.c: fix coding style.
  VFS: trivial optimization
  VFS: move flush member from vfs_s_subclass to vfs_class.
  VFS: move logfile member from vfs_s_subclass to vfs_class.
  VFS: change vfs_class::nothingisopen members
  vfs_class::nothingisopen: return gboolean instead of int.
  Rename VFS module initialization functions.
  lib/vfs/gc.c: yet another fixups
  VFS: invalidate file descriptors after close.
  Always use vfs_s_subclass as base class for VFS modules.
  (vfs_path_from_str_uri_parser): get rid of extra type cast.
  Ticket #3955: code cleanup before 4.8.23 release.
Andrew Borodin 5 years ago
parent
commit
846d92b9b7
10 changed files with 58 additions and 55 deletions
  1. 19 16
      lib/vfs/direntry.c
  2. 29 28
      lib/vfs/gc.c
  3. 2 3
      lib/vfs/path.c
  4. 3 1
      lib/vfs/vfs.h
  5. 0 2
      lib/vfs/xdirentry.h
  6. 1 1
      po/az.po
  7. 1 1
      po/be.po
  8. 1 1
      po/bg.po
  9. 1 1
      po/ca.po
  10. 1 1
      po/cs.po

+ 19 - 16
lib/vfs/direntry.c

@@ -420,11 +420,12 @@ vfs_s_opendir (const vfs_path_t * vpath)
     struct dirhandle *info;
     const vfs_path_element_t *path_element;
 
-    path_element = vfs_path_get_by_index (vpath, -1);
-
     dir = vfs_s_inode_from_path (vpath, FL_DIR | FL_FOLLOW);
     if (dir == NULL)
         return NULL;
+
+    path_element = vfs_path_get_by_index (vpath, -1);
+
     if (!S_ISDIR (dir->st.st_mode))
     {
         path_element->class->verrno = ENOTDIR;
@@ -520,12 +521,12 @@ vfs_s_readlink (const vfs_path_t * vpath, char *buf, size_t size)
     size_t len;
     const vfs_path_element_t *path_element;
 
-    path_element = vfs_path_get_by_index (vpath, -1);
-
     ino = vfs_s_inode_from_path (vpath, 0);
     if (ino == NULL)
         return (-1);
 
+    path_element = vfs_path_get_by_index (vpath, -1);
+
     if (!S_ISLNK (ino->st.st_mode))
     {
         path_element->class->verrno = EINVAL;
@@ -682,8 +683,12 @@ vfs_s_close (void *fh)
         }
         vfs_s_invalidate (me, super);
     }
+
     if (file->handle != -1)
+    {
         close (file->handle);
+        file->handle = -1;
+    }
 
     vfs_s_free_inode (me, file->ino);
     vfs_s_free_fh (sub, fh);
@@ -807,10 +812,10 @@ vfs_s_setctl (const vfs_path_t * vpath, int ctlop, void *arg)
             return 1;
         }
     case VFS_SETCTL_LOGFILE:
-        VFS_SUBCLASS (path_element->class)->logfile = fopen ((char *) arg, "w");
+        path_element->class->logfile = fopen ((char *) arg, "w");
         return 1;
     case VFS_SETCTL_FLUSH:
-        VFS_SUBCLASS (path_element->class)->flush = 1;
+        path_element->class->flush = TRUE;
         return 1;
     default:
         return 0;
@@ -835,12 +840,10 @@ vfs_s_getid (const vfs_path_t * vpath)
 
 /* --------------------------------------------------------------------------------------------- */
 
-static int
+static gboolean
 vfs_s_nothingisopen (vfsid id)
 {
-    (void) id;
-    /* Our data structures should survive free of superblock at any time */
-    return 1;
+    return (VFS_SUPER (id)->fd_usage <= 0);
 }
 
 /* --------------------------------------------------------------------------------------------- */
@@ -858,9 +861,9 @@ vfs_s_dir_uptodate (struct vfs_class *me, struct vfs_s_inode *ino)
 {
     struct timeval tim;
 
-    if (VFS_SUBCLASS (me)->flush != 0)
+    if (me->flush)
     {
-        VFS_SUBCLASS (me)->flush = 0;
+        me->flush = FALSE;
         return 0;
     }
 
@@ -869,7 +872,6 @@ vfs_s_dir_uptodate (struct vfs_class *me, struct vfs_s_inode *ino)
     return (tim.tv_sec < ino->timestamp.tv_sec ? 1 : 0);
 }
 
-
 /* --------------------------------------------------------------------------------------------- */
 /*** public functions ****************************************************************************/
 /* --------------------------------------------------------------------------------------------- */
@@ -1286,11 +1288,12 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
     const vfs_path_element_t *path_element;
     struct vfs_s_subclass *s;
 
-    path_element = vfs_path_get_by_index (vpath, -1);
-
     q = vfs_s_get_path (vpath, &super, 0);
     if (q == NULL)
         return NULL;
+
+    path_element = vfs_path_get_by_index (vpath, -1);
+
     ino = vfs_s_find_inode (path_element->class, super, q, LINK_FOLLOW, FL_NONE);
     if (ino != NULL && (flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
     {
@@ -1603,7 +1606,7 @@ vfs_s_select_on_two (int fd1, int fd2)
 int
 vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char term)
 {
-    FILE *logfile = VFS_SUBCLASS (me)->logfile;
+    FILE *logfile = me->logfile;
     int i;
     char c;
 

+ 29 - 28
lib/vfs/gc.c

@@ -45,6 +45,7 @@
 
 #include "lib/global.h"
 #include "lib/event.h"
+#include "lib/util.h"           /* MC_PTR_FREE */
 
 #include "vfs.h"
 #include "utilvfs.h"
@@ -109,7 +110,8 @@ static GSList *stamps = NULL;
 /*** file scope functions ************************************************************************/
 /* --------------------------------------------------------------------------------------------- */
 
-/** Compare two timeval structures. Return TRUE is t1 is less than t2. */
+/** Compare two timeval structures. Return TRUE if t1 is less than t2. */
+
 static gboolean
 timeoutcmp (const struct timeval *t1, const struct timeval *t2)
 {
@@ -236,19 +238,21 @@ vfs_stamp_create (struct vfs_class *vclass, vfsid id)
         mc_event_raise (MCEVENT_GROUP_CORE, "vfs_timestamp", (gpointer) & event_data);
 
         if (!event_data.ret && vclass != NULL && vclass->nothingisopen != NULL
-            && vclass->nothingisopen (id) != 0)
+            && vclass->nothingisopen (id))
             vfs_addstamp (vclass, id);
     }
 }
 
 /* --------------------------------------------------------------------------------------------- */
-/** This is called from timeout handler with now == FALSE,
-    or can be called with now == TRUE to force freeing all filesystems */
+/** This is called from timeout handler with now = FALSE,
+    or can be called with now = TRUE to force freeing all filesystems */
 
 void
 vfs_expire (gboolean now)
 {
     static gboolean locked = FALSE;
+    struct timeval curr_time, exp_time;
+    GSList *stamp;
 
     /* Avoid recursive invocation, e.g. when one of the free functions
        calls message */
@@ -256,48 +260,45 @@ vfs_expire (gboolean now)
         return;
     locked = TRUE;
 
+    gettimeofday (&curr_time, NULL);
+    exp_time.tv_sec = curr_time.tv_sec - vfs_timeout;
+    exp_time.tv_usec = curr_time.tv_usec;
+
     if (now)
     {
         /* reverse list to free nested VFSes at first */
         stamps = g_slist_reverse (stamps);
+    }
 
-        while (stamps != NULL)
-        {
-            struct vfs_stamping *stamping = VFS_STAMPING (stamps->data);
+    /* NULLize stamps that point to expired VFS */
+    for (stamp = stamps; stamp != NULL; stamp = g_slist_next (stamp))
+    {
+        struct vfs_stamping *stamping = VFS_STAMPING (stamp->data);
 
+        if (now)
+        {
+            /* free VFS forced */
             if (stamping->v->free != NULL)
                 stamping->v->free (stamping->id);
-            g_free (stamping);
-            stamps = g_slist_delete_link (stamps, stamps);
+            MC_PTR_FREE (stamp->data);
         }
-    }
-    else
-    {
-        struct timeval lc_time;
-        GSList *stamp;
-
-        gettimeofday (&lc_time, NULL);
-        lc_time.tv_sec -= vfs_timeout;
-
-        for (stamp = stamps; stamp != NULL;)
+        else if (timeoutcmp (&stamping->time, &exp_time))
         {
-            struct vfs_stamping *stamping = VFS_STAMPING (stamp->data);
-
-            if (!timeoutcmp (&stamping->time, &lc_time))
-                stamp = g_slist_next (stamp);
+            /* update timestamp of VFS that is in use, or free unused VFS */
+            if (stamping->v->nothingisopen != NULL && !stamping->v->nothingisopen (stamping->id))
+                stamping->time = curr_time;
             else
             {
-                GSList *st;
-
-                st = g_slist_next (stamp);
                 if (stamping->v->free != NULL)
                     stamping->v->free (stamping->id);
-                vfs_rmstamp (stamping->v, stamping->id);
-                stamp = st;
+                MC_PTR_FREE (stamp->data);
             }
         }
     }
 
+    /* then remove NULLized stamps */
+    stamps = g_slist_remove_all (stamps, NULL);
+
     locked = FALSE;
 }
 

+ 2 - 3
lib/vfs/path.c

@@ -445,7 +445,6 @@ vfs_path_from_str_uri_parser (char *path)
     {
         char *vfs_prefix_start;
         char *real_vfs_prefix_start = url_delimiter;
-        struct vfs_s_subclass *sub = NULL;
 
         while (real_vfs_prefix_start > path && !IS_PATH_SEP (*real_vfs_prefix_start))
             real_vfs_prefix_start--;
@@ -461,8 +460,8 @@ vfs_path_from_str_uri_parser (char *path)
         element->vfs_prefix = g_strdup (vfs_prefix_start);
 
         url_delimiter += strlen (VFS_PATH_URL_DELIMITER);
-        sub = VFS_SUBCLASS (element->class);
-        if (sub != NULL && (VFS_CLASS (sub)->flags & VFS_REMOTE) != 0)
+
+        if (element->class != NULL && (element->class->flags & VFS_REMOTE) != 0)
         {
             char *slash_pointer;
 

+ 3 - 1
lib/vfs/vfs.h

@@ -147,6 +147,8 @@ typedef struct vfs_class
     vfs_flags_t flags;
     const char *prefix;         /* "fish:" */
     int verrno;                 /* can't use errno because glibc2 might define errno as function */
+    gboolean flush;             /* if set to TRUE, invalidate directory cache */
+    FILE *logfile;
 
     /* *INDENT-OFF* */
     int (*init) (struct vfs_class * me);
@@ -193,7 +195,7 @@ typedef struct vfs_class
 
     vfsid (*getid) (const vfs_path_t * vpath);
 
-    int (*nothingisopen) (vfsid id);
+    gboolean (*nothingisopen) (vfsid id);
     void (*free) (vfsid id);
 
     vfs_path_t *(*getlocalcopy) (const vfs_path_t * vpath);

+ 0 - 2
lib/vfs/xdirentry.h

@@ -116,8 +116,6 @@ struct vfs_s_subclass
     GList *supers;
     int inode_counter;
     dev_t rdev;
-    FILE *logfile;
-    int flush;                  /* if set to 1, invalidate directory cache */
 
     /* *INDENT-OFF* */
     int (*init_inode) (struct vfs_class * me, struct vfs_s_inode * ino);        /* optional */

+ 1 - 1
po/az.po

@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Midnight Commander\n"
 "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
-"POT-Creation-Date: 2019-04-27 19:55+0300\n"
+"POT-Creation-Date: 2019-06-15 17:47+0300\n"
 "PO-Revision-Date: 2018-10-21 01:34+0000\n"
 "Last-Translator: Piotr Drąg <piotrdrag@gmail.com>\n"
 "Language-Team: Azerbaijani (http://www.transifex.com/mc/mc/language/az/)\n"

+ 1 - 1
po/be.po

@@ -11,7 +11,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Midnight Commander\n"
 "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
-"POT-Creation-Date: 2019-04-27 19:55+0300\n"
+"POT-Creation-Date: 2019-06-15 17:47+0300\n"
 "PO-Revision-Date: 2018-10-21 01:34+0000\n"
 "Last-Translator: Piotr Drąg <piotrdrag@gmail.com>\n"
 "Language-Team: Belarusian (http://www.transifex.com/mc/mc/language/be/)\n"

+ 1 - 1
po/bg.po

@@ -11,7 +11,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Midnight Commander\n"
 "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
-"POT-Creation-Date: 2019-04-27 19:55+0300\n"
+"POT-Creation-Date: 2019-06-15 17:47+0300\n"
 "PO-Revision-Date: 2018-10-21 01:34+0000\n"
 "Last-Translator: Piotr Drąg <piotrdrag@gmail.com>\n"
 "Language-Team: Bulgarian (http://www.transifex.com/mc/mc/language/bg/)\n"

+ 1 - 1
po/ca.po

@@ -16,7 +16,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Midnight Commander\n"
 "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
-"POT-Creation-Date: 2019-04-27 19:55+0300\n"
+"POT-Creation-Date: 2019-06-15 17:47+0300\n"
 "PO-Revision-Date: 2018-10-22 11:52+0000\n"
 "Last-Translator: Antoni Bella Pérez <antonibella5@yahoo.com>\n"
 "Language-Team: Catalan (http://www.transifex.com/mc/mc/language/ca/)\n"

+ 1 - 1
po/cs.po

@@ -13,7 +13,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Midnight Commander\n"
 "Report-Msgid-Bugs-To: http://www.midnight-commander.org/\n"
-"POT-Creation-Date: 2019-04-27 19:55+0300\n"
+"POT-Creation-Date: 2019-06-15 17:47+0300\n"
 "PO-Revision-Date: 2018-10-21 09:38+0000\n"
 "Last-Translator: Pavel Borecki <pavel.borecki@gmail.com>\n"
 "Language-Team: Czech (http://www.transifex.com/mc/mc/language/cs/)\n"

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