1
1

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 2011-05-01 12:16:46 +03:00
родитель c6796f790d
Коммит 8ea49095c3
16 изменённых файлов: 118 добавлений и 53 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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;
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -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 */

Просмотреть файл

@ -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)

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
/* }}} */
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -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))
{

Просмотреть файл

@ -1002,9 +1002,15 @@ prepend_cwd_on_local (const char *filename)
{
char *d;
size_t l;
vfs_path_t *vpath;
if (!vfs_file_is_local (filename) || g_path_is_absolute (filename))
vpath = vfs_path_from_str (filename);
if (!vfs_file_is_local (vpath) || g_path_is_absolute (filename))
{
vfs_path_free (vpath);
return g_strdup (filename);
}
vfs_path_free (vpath);
d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2);
mc_get_current_wd (d, MC_MAXPATHLEN);

Просмотреть файл

@ -1015,10 +1015,15 @@ show_free_space (WPanel * panel)
static struct my_statfs myfs_stats;
/* Old current working directory for displaying free space */
static char *old_cwd = NULL;
vfs_path_t *vpath = vfs_path_from_str (panel->cwd);
/* Don't try to stat non-local fs */
if (!vfs_file_is_local (panel->cwd) || !free_space)
if (!vfs_file_is_local (vpath) || !free_space)
{
vfs_path_free (vpath);
return;
}
vfs_path_free (vpath);
if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0)
{

Просмотреть файл

@ -248,22 +248,26 @@ tree_store_load_from (char *name)
different = strtok (NULL, "");
if (different)
{
vfs_path_t *vpath = vfs_path_from_str (oldname);
strcpy (oldname + common, different);
if (vfs_file_is_local (oldname))
if (vfs_file_is_local (vpath))
{
e = tree_store_add_entry (oldname);
e->scanned = scanned;
}
vfs_path_free (vpath);
}
}
}
else
{
if (vfs_file_is_local (lc_name))
vfs_path_t *vpath = vfs_path_from_str (lc_name);
if (vfs_file_is_local (vpath))
{
e = tree_store_add_entry (lc_name);
e->scanned = scanned;
}
vfs_path_free (vpath);
strcpy (oldname, lc_name);
}
g_free (lc_name);
@ -343,8 +347,9 @@ tree_store_save_to (char *name)
while (current)
{
int i, common;
vfs_path_t *vpath = vfs_path_from_str (current->name);
if (vfs_file_is_local (current->name))
if (vfs_file_is_local (vpath))
{
/* Clear-text compression */
if (current->prev && (common = str_common (current->prev->name, current->name)) > 2)
@ -366,9 +371,11 @@ tree_store_save_to (char *name)
{
fprintf (stderr, _("Cannot write to the %s file:\n%s\n"),
name, unix_error_string (errno));
vfs_path_free (vpath);
break;
}
}
vfs_path_free (vpath);
current = current->next;
}
tree_store_dirty (FALSE);

Просмотреть файл

@ -899,11 +899,14 @@ load_setup (void)
if (mc_run_param1 == NULL)
{
vfs_path_t *vpath;
buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", ".");
if (vfs_file_is_local (buffer))
vpath = vfs_path_from_str (buffer);
if (vfs_file_is_local (vpath))
mc_run_param1 = buffer;
else
g_free (buffer);
vfs_path_free (vpath);
}
boot_current_is_left = mc_config_get_bool (mc_panels_config, "Dirs", "current_is_left", TRUE);

Просмотреть файл

@ -395,15 +395,17 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc)
if (info->need_archive)
{
vfs_path_t *vpath = vfs_path_from_str (name);
if (mc_stat (name, &mystat) == -1)
return NULL;
if (!vfs_file_is_local (name))
if (!vfs_file_is_local (vpath))
{
local_name = mc_getlocalcopy (name);
if (local_name == NULL)
return NULL;
}
vfs_path_free (vpath);
tmp = name_quote (name, 0);
}

Просмотреть файл

@ -146,15 +146,17 @@ undelfs_shutdown (void)
/* --------------------------------------------------------------------------------------------- */
static void
undelfs_get_path (const char *dirname, char **fsname, char **file)
undelfs_get_path (const vfs_path_t * vpath, char **fsname, char **file)
{
const char *p;
const char *p, *dirname;
/* To look like filesystem, we have virtual directories
/#undel:XXX, which have no subdirectories. XXX is replaced with
hda5, sdb8 etc, which is assumed to live under /dev.
-- pavel@ucw.cz */
dirname = vpath->unparsed;
*fsname = NULL;
if (strncmp (dirname, "/#undel:", 8))
@ -336,7 +338,7 @@ undelfs_opendir (const vfs_path_t * vpath)
vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (vpath, -1);
undelfs_get_path (vpath->unparsed, &file, &f);
undelfs_get_path (vpath, &file, &f);
if (!file)
return 0;
@ -434,7 +436,7 @@ undelfs_open (const vfs_path_t * vpath, int flags, mode_t mode)
(void) mode;
/* Only allow reads on this file system */
undelfs_get_path (vpath->unparsed, &file, &f);
undelfs_get_path (vpath, &file, &f);
if (!file)
return 0;
@ -637,7 +639,7 @@ undelfs_lstat (const vfs_path_t * vpath, struct stat *buf)
int inode_index;
char *file, *f;
undelfs_get_path (vpath->unparsed, &file, &f);
undelfs_get_path (vpath, &file, &f);
if (!file)
return 0;
@ -689,7 +691,7 @@ undelfs_chdir (const vfs_path_t * vpath)
char *file, *f;
int fd;
undelfs_get_path (vpath->unparsed, &file, &f);
undelfs_get_path (vpath, &file, &f);
if (!file)
return -1;
@ -730,7 +732,7 @@ undelfs_getid (const vfs_path_t * vpath)
{
char *fname, *fsname;
undelfs_get_path (vpath->unparsed, &fsname, &fname);
undelfs_get_path (vpath, &fsname, &fname);
if (!fsname)
return NULL;