Browse Source

Changed interface of mc_stat() and mc_lstat() functions

...to handle vfs_path_t object as parameter.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Slava Zanko 13 years ago
parent
commit
eeaad790ab
10 changed files with 84 additions and 39 deletions
  1. 3 0
      lib/mcconfig.h
  2. 10 3
      lib/mcconfig/common.c
  3. 21 0
      lib/mcconfig/paths.c
  4. 12 5
      lib/util.c
  5. 6 9
      lib/vfs/interface.c
  6. 13 12
      lib/vfs/vfs.c
  7. 2 2
      lib/vfs/vfs.h
  8. 5 5
      lib/widget/input_complete.c
  9. 6 1
      src/args.c
  10. 6 2
      src/diffviewer/ydiff.c

+ 3 - 0
lib/mcconfig.h

@@ -1,6 +1,8 @@
 #ifndef MC_CONFIG_H
 #define MC_CONFIG_H
 
+#include "lib/vfs/vfs.h"        /* vfs_path_t */
+
 /*** typedefs(not structures) and defined constants **********************************************/
 
 #define CONFIG_APP_SECTION "Midnight-Commander"
@@ -110,6 +112,7 @@ const char *mc_config_get_home_dir (void);
 
 char *mc_config_get_full_path (const char *config_name);
 
+vfs_path_t *mc_config_get_full_vpath (const char *config_name);
 
 /*** inline functions ****************************************************************************/
 

+ 10 - 3
lib/mcconfig/common.c

@@ -115,10 +115,17 @@ mc_config_init (const gchar * ini_path)
     if (ini_path == NULL)
         return mc_config;
 
-    if (exist_file (ini_path) && mc_stat (ini_path, &st) == 0 && st.st_size != 0)
+    if (exist_file (ini_path))
     {
-        /* file exists and not empty */
-        g_key_file_load_from_file (mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL);
+        vfs_path_t *vpath;
+
+        vpath = vfs_path_from_str (ini_path);
+        if (mc_stat (vpath, &st) == 0 && st.st_size != 0)
+        {
+            /* file exists and not empty */
+            g_key_file_load_from_file (mc_config->handle, ini_path, G_KEY_FILE_KEEP_COMMENTS, NULL);
+        }
+        vfs_path_free (vpath);
     }
 
     mc_config->ini_path = g_strdup (ini_path);

+ 21 - 0
lib/mcconfig/paths.c

@@ -503,3 +503,24 @@ mc_config_get_full_path (const char *config_name)
 }
 
 /* --------------------------------------------------------------------------------------------- */
+/**
+ * Get full path to config file by short name.
+ *
+ * @param config_name short name
+ * @return object with full path to config file
+ */
+
+vfs_path_t *
+mc_config_get_full_vpath (const char *config_name)
+{
+    vfs_path_t *ret_vpath;
+    char *str_path;
+
+    str_path = mc_config_get_full_path (config_name);
+
+    ret_vpath = vfs_path_from_str(str_path);
+    g_free (str_path);
+    return ret_vpath;
+}
+
+/* --------------------------------------------------------------------------------------------- */

+ 12 - 5
lib/util.c

@@ -116,14 +116,18 @@ resolve_symlinks (const char *path)
     int len;
     struct stat mybuf;
     const char *p;
+    vfs_path_t *vpath;
 
     if (*path != PATH_SEP)
         return NULL;
+
+    vpath = vfs_path_from_str (path);
     r = buf = g_malloc (MC_MAXPATHLEN);
     buf2 = g_malloc (MC_MAXPATHLEN);
     *r++ = PATH_SEP;
     *r = 0;
     p = path;
+
     for (;;)
     {
         q = strchr (p + 1, PATH_SEP);
@@ -135,12 +139,12 @@ resolve_symlinks (const char *path)
         }
         c = *q;
         *q = 0;
-        if (mc_lstat (path, &mybuf) < 0)
+        if (mc_lstat (vpath, &mybuf) < 0)
         {
             g_free (buf);
-            g_free (buf2);
+            buf = NULL;
             *q = c;
-            return NULL;
+            goto ret;
         }
         if (!S_ISLNK (mybuf.st_mode))
             strcpy (r, p + 1);
@@ -150,9 +154,9 @@ resolve_symlinks (const char *path)
             if (len < 0)
             {
                 g_free (buf);
-                g_free (buf2);
+                buf = NULL;
                 *q = c;
-                return NULL;
+                goto ret;
             }
             buf2[len] = 0;
             if (*buf2 == PATH_SEP)
@@ -176,7 +180,10 @@ resolve_symlinks (const char *path)
         strcpy (buf, PATH_SEP_STR);
     else if (*(r - 1) == PATH_SEP && r != buf + 1)
         *(r - 1) = 0;
+
+ ret:
     g_free (buf2);
+    vfs_path_free (vpath);
     return buf;
 }
 

+ 6 - 9
lib/vfs/interface.c

@@ -80,6 +80,7 @@ mc_def_getlocalcopy (const char *filename)
     ssize_t i;
     char buffer[8192];
     struct stat mystat;
+    vfs_path_t *vpath = vfs_path_from_str (filename);
 
     fdin = mc_open (filename, O_RDONLY | O_LINEAR);
     if (fdin == -1)
@@ -106,12 +107,14 @@ mc_def_getlocalcopy (const char *filename)
         goto fail;
     }
 
-    if (mc_stat (filename, &mystat) != -1)
+    if (mc_stat (vpath, &mystat) != -1)
         chmod (tmp, mystat.st_mode);
+    vfs_path_free (vpath);
 
     return tmp;
 
   fail:
+    vfs_path_free (vpath);
     if (fdout != -1)
         close (fdout);
     if (fdin != -1)
@@ -556,13 +559,11 @@ mc_closedir (DIR * dirp)
 /* --------------------------------------------------------------------------------------------- */
 
 int
-mc_stat (const char *filename, struct stat *buf)
+mc_stat (const vfs_path_t * vpath, struct stat *buf)
 {
     int result = -1;
-    vfs_path_t *vpath;
     vfs_path_element_t *path_element;
 
-    vpath = vfs_path_from_str (filename);
     if (vpath == NULL)
         return -1;
 
@@ -575,20 +576,17 @@ mc_stat (const char *filename, struct stat *buf)
             errno = path_element->class->name ? vfs_ferrno (path_element->class) : E_NOTSUPP;
     }
 
-    vfs_path_free (vpath);
     return result;
 }
 
 /* --------------------------------------------------------------------------------------------- */
 
 int
-mc_lstat (const char *filename, struct stat *buf)
+mc_lstat (const vfs_path_t * vpath, struct stat *buf)
 {
     int result = -1;
-    vfs_path_t *vpath;
     vfs_path_element_t *path_element;
 
-    vpath = vfs_path_from_str (filename);
     if (vpath == NULL)
         return -1;
 
@@ -601,7 +599,6 @@ mc_lstat (const char *filename, struct stat *buf)
             errno = path_element->class->name ? vfs_ferrno (path_element->class) : E_NOTSUPP;
     }
 
-    vfs_path_free (vpath);
     return result;
 }
 

+ 13 - 12
lib/vfs/vfs.c

@@ -538,28 +538,29 @@ _vfs_get_cwd (void)
 
     path_element = vfs_path_get_by_index (vfs_get_raw_current_dir (), -1);
 
-    if (path_element->class->flags & VFSF_LOCAL)
+    if ((path_element->class->flags & VFSF_LOCAL) != 0)
     {
-        char *tmp;
+        char *current_dir;
+        vfs_path_t *tmp_vpath;
 
-        tmp = g_get_current_dir ();
-        if (tmp != NULL)
+        current_dir = g_get_current_dir ();
+        tmp_vpath = vfs_path_from_str (current_dir);
+        g_free (current_dir);
+
+        if (tmp_vpath != NULL)
         {                       /* One of the directories in the path is not readable */
             struct stat my_stat, my_stat2;
 
             /* Check if it is O.K. to use the current_dir */
             if (!(mc_global.vfs.cd_symlinks
-                  && mc_stat (tmp, &my_stat) == 0
-                  && mc_stat (path_element->path, &my_stat2) == 0
+                  && mc_stat (tmp_vpath, &my_stat) == 0
+                  && mc_stat (vfs_get_raw_current_dir (), &my_stat2) == 0
                   && my_stat.st_ino == my_stat2.st_ino && my_stat.st_dev == my_stat2.st_dev))
-            {
-                vfs_set_raw_current_dir (vfs_path_from_str (tmp));
-            }
-
-            g_free (tmp);
+                vfs_set_raw_current_dir (tmp_vpath);
+            else
+                vfs_path_free (tmp_vpath);
         }
     }
-
     return vfs_path_to_str (vfs_get_raw_current_dir ());
 }
 

+ 2 - 2
lib/vfs/vfs.h

@@ -282,13 +282,13 @@ off_t mc_lseek (int fd, off_t offset, int whence);
 DIR *mc_opendir (const char *dirname);
 struct dirent *mc_readdir (DIR * dirp);
 int mc_closedir (DIR * dir);
-int mc_stat (const char *path, struct stat *buf);
+int mc_stat (const vfs_path_t * vpath, struct stat *buf);
 int mc_mknod (const char *path, mode_t mode, dev_t dev);
 int mc_link (const char *name1, const char *name2);
 int mc_mkdir (const char *path, mode_t mode);
 int mc_rmdir (const char *path);
 int mc_fstat (int fd, struct stat *buf);
-int mc_lstat (const char *path, struct stat *buf);
+int mc_lstat (const vfs_path_t * vpath, struct stat *buf);
 int mc_symlink (const char *name1, const char *name2);
 int mc_rename (const char *original, const char *target);
 int mc_chmod (const char *path, mode_t mode);

+ 5 - 5
lib/widget/input_complete.c

@@ -209,13 +209,13 @@ filename_completion_function (const char *text, int state, input_complete_t flag
         isdir = 1;
         isexec = 0;
         {
-            char *tmp;
+            vfs_path_t *vpath;
             struct stat tempstat;
 
-            tmp = g_strconcat (dirname, PATH_SEP_STR, entry->d_name, (char *) NULL);
-            canonicalize_pathname (tmp);
+            vpath = vfs_path_build_filename (dirname, entry->d_name, (char *) NULL);
+
             /* Unix version */
-            if (!mc_stat (tmp, &tempstat))
+            if (mc_stat (vpath, &tempstat) == 0)
             {
                 uid_t my_uid = getuid ();
                 gid_t my_gid = getgid ();
@@ -235,7 +235,7 @@ filename_completion_function (const char *text, int state, input_complete_t flag
                 /* stat failed, strange. not a dir in any case */
                 isdir = 0;
             }
-            g_free (tmp);
+            vfs_path_free (vpath);
         }
         if ((flags & INPUT_COMPLETE_COMMANDS) && (isexec || isdir))
             break;

+ 6 - 1
src/args.c

@@ -466,13 +466,16 @@ mc_setup_by_args (int argc, char *argv[])
             {
                 char *fname;
                 struct stat st;
+                vfs_path_t *tmp_vpath, *fname_vpath;
 
                 fname = g_strndup (tmp, p - 1 - tmp);
+                tmp_vpath = vfs_path_from_str (tmp);
+                fname_vpath = vfs_path_from_str (fname);
                 /*
                  * Check that the file before the colon actually exists.
                  * If it doesn't exist, revert to the old behavior.
                  */
-                if (mc_stat (tmp, &st) == -1 && mc_stat (fname, &st) != -1)
+                if (mc_stat (tmp_vpath, &st) == -1 && mc_stat (fname_vpath, &st) != -1)
                 {
                     mc_run_param0 = fname;
                     mc_args__edit_start_line = atoi (p);
@@ -482,6 +485,8 @@ mc_setup_by_args (int argc, char *argv[])
                     g_free (fname);
                     goto try_plus_filename;
                 }
+                vfs_path_free (tmp_vpath);
+                vfs_path_free (fname_vpath);
             }
             else
             {

+ 6 - 2
src/diffviewer/ydiff.c

@@ -3335,9 +3335,11 @@ do \
         real_file##n = mc_getlocalcopy (file##n); \
         if (real_file##n != NULL) \
         { \
+            vfs_path_t *tmp_vpath = vfs_path_from_str (real_file##n); \
             use_copy##n = 1; \
-            if (mc_stat (real_file##n, &st##n) != 0) \
+            if (mc_stat (tmp_vpath, &st##n) != 0) \
                 use_copy##n = -1; \
+            vfs_path_free (tmp_vpath); \
         } \
     } \
     vfs_path_free(vpath); \
@@ -3353,9 +3355,11 @@ do \
         if (use_copy##n > 0) \
         { \
             time_t mtime; \
+            vfs_path_t *tmp_vpath = vfs_path_from_str (real_file##n); \
             mtime = st##n.st_mtime; \
-            if (mc_stat (real_file##n, &st##n) == 0) \
+            if (mc_stat (tmp_vpath, &st##n) == 0) \
                 changed = (mtime != st##n.st_mtime); \
+            vfs_path_free (tmp_vpath); \
         } \
         mc_ungetlocalcopy (file##n, real_file##n, changed); \
         g_free (real_file##n); \

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