Browse Source

Changed functions vfs_file_is_local() and vfs_file_class_flags() for handle vfs_path_t type

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Slava Zanko 14 years ago
parent
commit
8ea49095c3
10 changed files with 79 additions and 39 deletions
  1. 6 1
      lib/lock.c
  2. 6 10
      lib/vfs/vfs.c
  3. 2 2
      lib/vfs/vfs.h
  4. 3 1
      src/diffviewer/ydiff.c
  5. 12 10
      src/editor/edit.c
  6. 3 2
      src/editor/editcmd.c
  7. 4 1
      src/execute.c
  8. 7 2
      src/filemanager/ext.c
  9. 27 8
      src/filemanager/file.c
  10. 9 2
      src/filemanager/filenot.c

+ 6 - 1
lib/lock.c

@@ -197,6 +197,7 @@ lock_file (const char *fname)
     struct stat statbuf;
     struct lock_s *lockinfo;
     gboolean symlink_ok;
+    vfs_path_t *vpath;
 
     /* Just to be sure (and don't lock new file) */
     if (fname == NULL || *fname == '\0')
@@ -204,12 +205,16 @@ lock_file (const char *fname)
 
     fname = tilde_expand (fname);
 
+    vpath = vfs_path_from_str (fname);
+
     /* Locking on VFS is not supported */
-    if (!vfs_file_is_local (fname))
+    if (!vfs_file_is_local (vpath))
     {
         g_free ((gpointer) fname);
+        vfs_path_free (vpath);
         return 0;
     }
+    vfs_path_free (vpath);
 
     /* Check if already locked */
     lockfname = lock_build_symlink_name (fname);

+ 6 - 10
lib/vfs/vfs.c

@@ -576,18 +576,14 @@ vfs_current_is_local (void)
 /* Return flags of the VFS class of the given filename */
 
 vfs_class_flags_t
-vfs_file_class_flags (const char *filename)
+vfs_file_class_flags (const vfs_path_t * vpath)
 {
-    struct vfs_class *vfs;
-    char *fname;
+    vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1);
 
-    fname = vfs_canon_and_translate (filename);
-    if (fname == NULL)
+    if (path_element == NULL)
         return VFSF_UNKNOWN;
 
-    vfs = vfs_get_class (fname);
-    g_free (fname);
-    return vfs->flags;
+    return path_element->class->flags;
 }
 
 /* --------------------------------------------------------------------------------------------- */
@@ -691,9 +687,9 @@ vfs_translate_url (const char *url)
 /* --------------------------------------------------------------------------------------------- */
 
 gboolean
-vfs_file_is_local (const char *filename)
+vfs_file_is_local (const vfs_path_t * vpath)
 {
-    return (vfs_file_class_flags (filename) & VFSF_LOCAL) != 0;
+    return (vfs_file_class_flags (vpath) & VFSF_LOCAL) != 0;
 }
 
 /* --------------------------------------------------------------------------------------------- */

+ 2 - 2
lib/vfs/vfs.h

@@ -234,7 +234,7 @@ void vfs_set_raw_current_dir (const vfs_path_t * vpath);
 
 
 gboolean vfs_current_is_local (void);
-gboolean vfs_file_is_local (const char *filename);
+gboolean vfs_file_is_local (const vfs_path_t * vpath);
 
 char *vfs_canon (const char *path);
 char *vfs_strip_suffix_from_filename (const char *filename);
@@ -244,7 +244,7 @@ struct vfs_class *vfs_split (char *path, char **inpath, char **op);
 char *vfs_path (const char *path);
 
 struct vfs_class *vfs_get_class (const char *path);
-vfs_class_flags_t vfs_file_class_flags (const char *filename);
+vfs_class_flags_t vfs_file_class_flags (const vfs_path_t * vpath);
 
 /* return encoding after last #enc: or NULL, if part does not contain #enc:
  * return static buffer */

+ 3 - 1
src/diffviewer/ydiff.c

@@ -3332,9 +3332,10 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
 #define GET_FILE_AND_STAMP(n) \
 do \
 { \
+    vfs_path_t *vpath = vfs_path_from_str(file##n); \
     use_copy##n = 0; \
     real_file##n = file##n; \
-    if (!vfs_file_is_local (file##n)) \
+    if (!vfs_file_is_local (vpath)) \
     { \
         real_file##n = mc_getlocalcopy (file##n); \
         if (real_file##n != NULL) \
@@ -3344,6 +3345,7 @@ do \
                 use_copy##n = -1; \
         } \
     } \
+    vfs_path_free(vpath); \
 } \
 while (0)
 

+ 12 - 10
src/editor/edit.c

@@ -432,6 +432,7 @@ static int
 edit_load_file (WEdit * edit)
 {
     int fast_load = 1;
+    vfs_path_t *vpath = vfs_path_from_str (edit->filename);
 
     /* Cannot do fast load if a filter is used */
     if (edit_find_filter (edit->filename) >= 0)
@@ -441,8 +442,9 @@ edit_load_file (WEdit * edit)
      * VFS may report file size incorrectly, and slow load is not a big
      * deal considering overhead in VFS.
      */
-    if (!vfs_file_is_local (edit->filename))
+    if (!vfs_file_is_local (vpath))
         fast_load = 0;
+    vfs_path_free (vpath);
 
     /*
      * FIXME: line end translation should disable fast loading as well
@@ -1599,7 +1601,7 @@ edit_get_bracket (WEdit * edit, int in_screen, unsigned long furthest_bracket_se
                 break;
             /* count lines if searching downward */
             if (inc > 0 && a == '\n')
-                if (n++ >= edit->widget.lines - edit->curs_row)     /* out of screen */
+                if (n++ >= edit->widget.lines - edit->curs_row) /* out of screen */
                     break;
         }
         /* count bracket depth */
@@ -2320,7 +2322,9 @@ edit_set_codeset (WEdit * edit)
 #ifdef HAVE_CHARSET
     const char *cp_id;
 
-    cp_id = get_codepage_id (mc_global.source_codepage >= 0 ? mc_global.source_codepage : mc_global.display_codepage);
+    cp_id =
+        get_codepage_id (mc_global.source_codepage >=
+                         0 ? mc_global.source_codepage : mc_global.display_codepage);
 
     if (cp_id != NULL)
     {
@@ -3427,7 +3431,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
 
     switch (command)
     {
-    /* a mark command with shift-arrow */
+        /* a mark command with shift-arrow */
     case CK_MarkLeft:
     case CK_MarkRight:
     case CK_MarkToWordBegin:
@@ -3446,7 +3450,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
     case CK_MarkScrollDown:
     case CK_MarkParagraphUp:
     case CK_MarkParagraphDown:
-    /* a mark command with alt-arrow */
+        /* a mark command with alt-arrow */
     case CK_MarkColumnPageUp:
     case CK_MarkColumnPageDown:
     case CK_MarkColumnLeft:
@@ -3466,7 +3470,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
         edit->highlight = 1;
         break;
 
-    /* any other command */
+        /* any other command */
     default:
         if (edit->highlight)
             edit_mark_cmd (edit, 0);    /* clear */
@@ -3914,8 +3918,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
             if (p->next)
             {
                 p = p->next;
-                if (p->line >= edit->start_line + edit->widget.lines
-                    || p->line < edit->start_line)
+                if (p->line >= edit->start_line + edit->widget.lines || p->line < edit->start_line)
                     edit_move_display (edit, p->line - edit->widget.lines / 2);
                 edit_move_to_line (edit, p->line);
             }
@@ -3931,8 +3934,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
                     p = p->prev;
             if (p->line >= 0)
             {
-                if (p->line >= edit->start_line + edit->widget.lines
-                    || p->line < edit->start_line)
+                if (p->line >= edit->start_line + edit->widget.lines || p->line < edit->start_line)
                     edit_move_display (edit, p->line - edit->widget.lines / 2);
                 edit_move_to_line (edit, p->line);
             }

+ 3 - 2
src/editor/editcmd.c

@@ -143,8 +143,8 @@ edit_save_file (WEdit * edit, const char *filename)
     this_save_mode = option_save_mode;
     if (this_save_mode != EDIT_QUICK_SAVE)
     {
-        if (!vfs_file_is_local (real_filename) ||
-            (fd = mc_open (real_filename, O_RDONLY | O_BINARY)) == -1)
+        vfs_path_t *vpath = vfs_path_from_str (real_filename);
+        if (!vfs_file_is_local (vpath) || (fd = mc_open (real_filename, O_RDONLY | O_BINARY)) == -1)
         {
             /*
              * The file does not exists yet, so no safe save or
@@ -152,6 +152,7 @@ edit_save_file (WEdit * edit, const char *filename)
              */
             this_save_mode = EDIT_QUICK_SAVE;
         }
+        vfs_path_free (vpath);
         if (fd != -1)
             mc_close (fd);
     }

+ 4 - 1
src/execute.c

@@ -432,15 +432,18 @@ execute_with_vfs_arg (const char *command, const char *filename)
     char *fn;
     struct stat st;
     time_t mtime;
+    vfs_path_t *vpath = vfs_path_from_str (filename);
 
     /* Simplest case, this file is local */
-    if (!filename || vfs_file_is_local (filename))
+    if (!filename || vfs_file_is_local (vpath))
     {
         fn = vfs_canon_and_translate (filename);
         do_execute (command, fn, EXECUTE_INTERNAL);
         g_free (fn);
+        vfs_path_free (vpath);
         return;
     }
+    vfs_path_free (vpath);
 
     /* FIXME: Creation of new files on VFS is not supported */
     if (!*filename)

+ 7 - 2
src/filemanager/ext.c

@@ -106,16 +106,20 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
     time_t localmtime = 0;
     struct stat mystat;
     quote_func_t quote_func = name_quote;
+    vfs_path_t *vpath;
 
     g_return_if_fail (filename != NULL);
     g_return_if_fail (lc_data != NULL);
 
+    vpath = vfs_path_from_str (filename);
+
     /* Avoid making a local copy if we are doing a cd */
-    if (!vfs_file_is_local (filename))
+    if (!vfs_file_is_local (vpath))
         do_local_copy = 1;
     else
         do_local_copy = 0;
 
+    vfs_path_free (vpath);
     /*
      * All commands should be run in /bin/sh regardless of user shell.
      * To do that, create temporary shell script and run it.
@@ -683,7 +687,8 @@ regex_command (const char *filename, const char *action, int *move_dir)
                      _("The format of the %s%s%s file has "
                        "changed with version 3.0. You may either want to copy "
                        "it from %smc.ext or use that file as an example of how to write it."),
-                     mc_config_get_data_path (), PATH_SEP_STR, MC_FILEBIND_FILE, mc_global.sysconfig_dir);
+                     mc_config_get_data_path (), PATH_SEP_STR, MC_FILEBIND_FILE,
+                     mc_global.sysconfig_dir);
             g_free (title);
         }
     }

+ 27 - 8
src/filemanager/file.c

@@ -250,7 +250,9 @@ is_in_linklist (struct link *lp, const char *path, struct stat *sb)
 
 /* --------------------------------------------------------------------------------------------- */
 /**
- * Returns 0 if the inode wasn't found in the cache and 1 if it was found
+ * Check and made hardlink
+ *
+ * @return FALSE if the inode wasn't found in the cache and TRUE if it was found
  * and a hardlink was succesfully made
  */
 
@@ -258,14 +260,23 @@ static int
 check_hardlinks (const char *src_name, const char *dst_name, struct stat *pstat)
 {
     struct link *lp;
-    struct vfs_class *my_vfs = vfs_get_class (src_name);
+    vfs_path_t *vpath;
+
+    struct vfs_class *my_vfs;
     ino_t ino = pstat->st_ino;
     dev_t dev = pstat->st_dev;
     struct stat link_stat;
     const char *p;
 
-    if ((vfs_file_class_flags (src_name) & VFSF_NOLINKS) != 0)
-        return 0;
+    vpath = vfs_path_from_str (src_name);
+
+    if ((vfs_file_class_flags (vpath) & VFSF_NOLINKS) != 0)
+    {
+        vfs_path_free (vpath);
+        return FALSE;
+    }
+    my_vfs = vfs_path_get_by_index (vpath, -1)->class;
+    vfs_path_free (vpath);
 
     for (lp = linklist; lp != NULL; lp = lp->next)
         if (lp->vfs == my_vfs && lp->ino == ino && lp->dev == dev)
@@ -280,12 +291,12 @@ check_hardlinks (const char *src_name, const char *dst_name, struct stat *pstat)
                     if (!mc_stat (p, &link_stat))
                     {
                         if (!mc_link (p, dst_name))
-                            return 1;
+                            return TRUE;
                     }
                 }
             }
             message (D_ERROR, MSG_ERROR, _("Cannot make the hardlink"));
-            return 0;
+            return FALSE;
         }
     lp = (struct link *) g_try_malloc (sizeof (struct link) + strlen (src_name)
                                        + strlen (dst_name) + 1);
@@ -301,7 +312,7 @@ check_hardlinks (const char *src_name, const char *dst_name, struct stat *pstat)
         lp->next = linklist;
         linklist = lp;
     }
-    return 0;
+    return FALSE;
 }
 
 /* --------------------------------------------------------------------------------------------- */
@@ -336,13 +347,20 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path)
     link_target[len] = 0;
 
     if (ctx->stable_symlinks)
-        if (!vfs_file_is_local (src_path) || !vfs_file_is_local (dst_path))
+    {
+        vfs_path_t *vpath1 = vfs_path_from_str (src_path);
+        vfs_path_t *vpath2 = vfs_path_from_str (dst_path);
+
+        if (!vfs_file_is_local (vpath1) || !vfs_file_is_local (vpath2))
         {
             message (D_ERROR, MSG_ERROR,
                      _("Cannot make stable symlinks across"
                        "non-local filesystems:\n\nOption Stable Symlinks will be disabled"));
             ctx->stable_symlinks = FALSE;
         }
+        vfs_path_free (vpath1);
+        vfs_path_free (vpath2);
+    }
 
     if (ctx->stable_symlinks && !g_path_is_absolute (link_target))
     {
@@ -650,6 +668,7 @@ files_error (const char *format, const char *file1, const char *file2)
 
     return do_file_error (buf);
 }
+
 /* }}} */
 
 /* --------------------------------------------------------------------------------------------- */

+ 9 - 2
src/filemanager/filenot.c

@@ -75,8 +75,15 @@ my_mkdir_rec (char *s, mode_t mode)
         return -1;
 
     /* FIXME: should check instead if s is at the root of that filesystem */
-    if (!vfs_file_is_local (s))
-        return -1;
+    {
+        vfs_path_t *vpath = vfs_path_from_str (s);
+        if (!vfs_file_is_local (vpath))
+        {
+            vfs_path_free (vpath);
+            return -1;
+        }
+        vfs_path_free (vpath);
+    }
 
     if (!strcmp (s, PATH_SEP_STR))
     {

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