Removed vfs_get_class() function
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
родитель
922114a1d0
Коммит
3d1e2df9b7
@ -8,7 +8,6 @@ LIBS=@CHECK_LIBS@ \
|
|||||||
|
|
||||||
TESTS = \
|
TESTS = \
|
||||||
current_dir \
|
current_dir \
|
||||||
get_vfs_class \
|
|
||||||
path_serialize \
|
path_serialize \
|
||||||
vfs_path_string_convert \
|
vfs_path_string_convert \
|
||||||
vfs_prefix_to_class \
|
vfs_prefix_to_class \
|
||||||
@ -20,9 +19,6 @@ check_PROGRAMS = $(TESTS)
|
|||||||
current_dir_SOURCES = \
|
current_dir_SOURCES = \
|
||||||
current_dir.c
|
current_dir.c
|
||||||
|
|
||||||
get_vfs_class_SOURCES = \
|
|
||||||
get_vfs_class.c
|
|
||||||
|
|
||||||
path_serialize_SOURCES = \
|
path_serialize_SOURCES = \
|
||||||
path_serialize.c
|
path_serialize.c
|
||||||
|
|
||||||
|
@ -1,162 +0,0 @@
|
|||||||
/* lib/vfs - get vfs class from string
|
|
||||||
|
|
||||||
Copyright (C) 2011 Free Software Foundation, Inc.
|
|
||||||
|
|
||||||
Written by:
|
|
||||||
Slava Zanko <slavazanko@gmail.com>, 2011
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public License
|
|
||||||
as published by the Free Software Foundation; either version 2 of
|
|
||||||
the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define TEST_SUITE_NAME "/lib/vfs"
|
|
||||||
|
|
||||||
#include <check.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "lib/global.h"
|
|
||||||
#include "lib/strutil.h"
|
|
||||||
#include "lib/vfs/xdirentry.h"
|
|
||||||
#include "lib/vfs/vfs.c" /* for testing static methods */
|
|
||||||
|
|
||||||
#include "src/vfs/local/local.c"
|
|
||||||
|
|
||||||
static void
|
|
||||||
setup (void)
|
|
||||||
{
|
|
||||||
str_init_strings (NULL);
|
|
||||||
|
|
||||||
vfs_init ();
|
|
||||||
init_localfs ();
|
|
||||||
vfs_setup_work_dir ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
teardown (void)
|
|
||||||
{
|
|
||||||
vfs_shut ();
|
|
||||||
str_uninit_strings ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
START_TEST (test_register_vfs_class)
|
|
||||||
{
|
|
||||||
static struct vfs_s_subclass test_subclass;
|
|
||||||
static struct vfs_class vfs_test_ops;
|
|
||||||
|
|
||||||
test_subclass.flags = VFS_S_REMOTE;
|
|
||||||
vfs_s_init_class (&vfs_test_ops, &test_subclass);
|
|
||||||
|
|
||||||
vfs_test_ops.name = "testfs";
|
|
||||||
vfs_test_ops.flags = VFSF_NOLINKS;
|
|
||||||
vfs_test_ops.prefix = "test:";
|
|
||||||
vfs_register_class (&vfs_test_ops);
|
|
||||||
|
|
||||||
fail_if (vfs__classes_list->len != 2, "Failed to register test VFS module");;
|
|
||||||
|
|
||||||
{
|
|
||||||
struct vfs_class *result;
|
|
||||||
result = vfs_get_class("/#test://bla-bla/some/path");
|
|
||||||
fail_if(result == NULL, "VFS module not found!");
|
|
||||||
fail_unless(result == &vfs_test_ops, "Result(%p) don't match to vfs_test_ops(%p)!", result, &vfs_test_ops);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
struct vfs_class *result;
|
|
||||||
result = vfs_get_class("/#test://bla-bla/some/path/#test_not_exists://bla-bla/some/path");
|
|
||||||
fail_if(result == NULL, "VFS module not found!");
|
|
||||||
fail_unless(result == &vfs_test_ops, "Result(%p) don't match to vfs_test_ops(%p)!", result, &vfs_test_ops);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
END_TEST
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
START_TEST (test_register_vfs_class2)
|
|
||||||
{
|
|
||||||
static struct vfs_s_subclass test_subclass1, test_subclass2;
|
|
||||||
static struct vfs_class vfs_test_ops1, vfs_test_ops2;
|
|
||||||
|
|
||||||
test_subclass1.flags = VFS_S_REMOTE;
|
|
||||||
vfs_s_init_class (&vfs_test_ops1, &test_subclass1);
|
|
||||||
|
|
||||||
vfs_test_ops1.name = "testfs1";
|
|
||||||
vfs_test_ops1.flags = VFSF_NOLINKS;
|
|
||||||
vfs_test_ops1.prefix = "test1:";
|
|
||||||
vfs_register_class (&vfs_test_ops1);
|
|
||||||
|
|
||||||
vfs_s_init_class (&vfs_test_ops2, &test_subclass2);
|
|
||||||
|
|
||||||
vfs_test_ops2.name = "testfs2";
|
|
||||||
vfs_test_ops2.prefix = "test2:";
|
|
||||||
vfs_register_class (&vfs_test_ops2);
|
|
||||||
|
|
||||||
|
|
||||||
fail_if (vfs__classes_list->len != 3, "Failed to register test VFS module");;
|
|
||||||
|
|
||||||
{
|
|
||||||
struct vfs_class *result;
|
|
||||||
result = vfs_get_class("/#test1://bla-bla/some/path");
|
|
||||||
fail_if(result == NULL, "VFS module not found!");
|
|
||||||
fail_unless(result == &vfs_test_ops1, "Result(%p) don't match to vfs_test_ops1(%p)!", result, &vfs_test_ops1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
struct vfs_class *result;
|
|
||||||
result = vfs_get_class("/#test2://bla-bla/some/path/#test1://bla-bla/some/path");
|
|
||||||
fail_if(result == NULL, "VFS module not found!");
|
|
||||||
fail_unless(result == &vfs_test_ops1, "Result(%p) don't match to vfs_test_ops1(%p)!", result, &vfs_test_ops1);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
struct vfs_class *result;
|
|
||||||
result = vfs_get_class("/#test1://bla-bla/some/path/#test2://bla-bla/some/path");
|
|
||||||
fail_if(result == NULL, "VFS module not found!");
|
|
||||||
fail_unless(result == &vfs_test_ops2, "Result(%p) don't match to vfs_test_ops2(%p)!", result, &vfs_test_ops2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
END_TEST
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
int
|
|
||||||
main (void)
|
|
||||||
{
|
|
||||||
int number_failed;
|
|
||||||
|
|
||||||
Suite *s = suite_create (TEST_SUITE_NAME);
|
|
||||||
TCase *tc_core = tcase_create ("Core");
|
|
||||||
SRunner *sr;
|
|
||||||
|
|
||||||
tcase_add_checked_fixture (tc_core, setup, teardown);
|
|
||||||
|
|
||||||
/* Add new tests here: *************** */
|
|
||||||
tcase_add_test (tc_core, test_register_vfs_class);
|
|
||||||
tcase_add_test (tc_core, test_register_vfs_class2);
|
|
||||||
/* *********************************** */
|
|
||||||
|
|
||||||
suite_add_tcase (s, tc_core);
|
|
||||||
sr = srunner_create (s);
|
|
||||||
srunner_set_log (sr, "get_vfs_class.log");
|
|
||||||
srunner_run_all (sr, CK_NORMAL);
|
|
||||||
number_failed = srunner_ntests_failed (sr);
|
|
||||||
srunner_free (sr);
|
|
||||||
return (number_failed == 0) ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
@ -112,47 +112,6 @@ static const struct
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*** file scope functions ************************************************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
path_magic (const char *path)
|
|
||||||
{
|
|
||||||
struct stat buf;
|
|
||||||
|
|
||||||
return (stat (path, &buf) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
static struct vfs_class *
|
|
||||||
_vfs_get_class (char *path)
|
|
||||||
{
|
|
||||||
char *semi;
|
|
||||||
char *slash;
|
|
||||||
struct vfs_class *ret;
|
|
||||||
|
|
||||||
g_return_val_if_fail (path, NULL);
|
|
||||||
|
|
||||||
semi = strrchr (path, '#');
|
|
||||||
if (semi == NULL || !path_magic (path))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
slash = strchr (semi, PATH_SEP);
|
|
||||||
*semi = '\0';
|
|
||||||
if (slash != NULL)
|
|
||||||
*slash = '\0';
|
|
||||||
|
|
||||||
ret = vfs_prefix_to_class (semi + 1);
|
|
||||||
|
|
||||||
if (slash != NULL)
|
|
||||||
*slash = PATH_SEP;
|
|
||||||
if (ret == NULL)
|
|
||||||
ret = _vfs_get_class (path);
|
|
||||||
|
|
||||||
*semi = '#';
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* now used only by vfs_translate_path, but could be used in other vfs
|
/* now used only by vfs_translate_path, but could be used in other vfs
|
||||||
* plugin to automatic detect encoding
|
* plugin to automatic detect encoding
|
||||||
@ -394,24 +353,6 @@ vfs_strip_suffix_from_filename (const char *filename)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
struct vfs_class *
|
|
||||||
vfs_get_class (const char *pathname)
|
|
||||||
{
|
|
||||||
char *path;
|
|
||||||
struct vfs_class *vfs;
|
|
||||||
|
|
||||||
path = g_strdup (pathname);
|
|
||||||
vfs = _vfs_get_class (path);
|
|
||||||
g_free (path);
|
|
||||||
|
|
||||||
if (vfs == NULL)
|
|
||||||
vfs = g_ptr_array_index (vfs__classes_list, 0); /* localfs */
|
|
||||||
|
|
||||||
return vfs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
vfs_translate_path (const char *path)
|
vfs_translate_path (const char *path)
|
||||||
{
|
{
|
||||||
@ -629,7 +570,7 @@ vfs_print_message (const char *msg, ...)
|
|||||||
char *
|
char *
|
||||||
_vfs_get_cwd (void)
|
_vfs_get_cwd (void)
|
||||||
{
|
{
|
||||||
char *trans, *curr_dir;
|
vfs_path_element_t *path_element;
|
||||||
|
|
||||||
if (vfs_get_raw_current_dir () == NULL)
|
if (vfs_get_raw_current_dir () == NULL)
|
||||||
{
|
{
|
||||||
@ -638,13 +579,10 @@ _vfs_get_cwd (void)
|
|||||||
vfs_set_raw_current_dir (vfs_path_from_str (tmp));
|
vfs_set_raw_current_dir (vfs_path_from_str (tmp));
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
}
|
}
|
||||||
|
path_element = vfs_path_get_by_index (vfs_get_raw_current_dir (), -1);
|
||||||
|
|
||||||
curr_dir = vfs_get_current_dir ();
|
if (path_element->class->flags & VFSF_LOCAL)
|
||||||
trans = vfs_translate_path_n (curr_dir);
|
|
||||||
|
|
||||||
if (_vfs_get_class (trans) == NULL)
|
|
||||||
{
|
{
|
||||||
vfs_path_element_t *path_element = vfs_path_get_by_index (vfs_get_raw_current_dir (), -1);
|
|
||||||
|
|
||||||
if (path_element->encoding == NULL)
|
if (path_element->encoding == NULL)
|
||||||
{
|
{
|
||||||
@ -665,7 +603,7 @@ _vfs_get_cwd (void)
|
|||||||
/* Check if it is O.K. to use the current_dir */
|
/* Check if it is O.K. to use the current_dir */
|
||||||
if (!(mc_global.vfs.cd_symlinks
|
if (!(mc_global.vfs.cd_symlinks
|
||||||
&& mc_stat (vfs_str_buffer->str, &my_stat) == 0
|
&& mc_stat (vfs_str_buffer->str, &my_stat) == 0
|
||||||
&& mc_stat (curr_dir, &my_stat2) == 0
|
&& mc_stat (path_element->path, &my_stat2) == 0
|
||||||
&& my_stat.st_ino == my_stat2.st_ino
|
&& my_stat.st_ino == my_stat2.st_ino
|
||||||
&& my_stat.st_dev == my_stat2.st_dev))
|
&& my_stat.st_dev == my_stat2.st_dev))
|
||||||
{
|
{
|
||||||
@ -676,8 +614,7 @@ _vfs_get_cwd (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (trans);
|
return vfs_path_to_str (vfs_get_raw_current_dir ());
|
||||||
return curr_dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -242,7 +242,6 @@ char *vfs_translate_url (const char *url);
|
|||||||
struct vfs_class *vfs_split (char *path, char **inpath, char **op);
|
struct vfs_class *vfs_split (char *path, char **inpath, char **op);
|
||||||
char *vfs_path (const char *path);
|
char *vfs_path (const char *path);
|
||||||
|
|
||||||
struct vfs_class *vfs_get_class (const char *path);
|
|
||||||
vfs_class_flags_t vfs_file_class_flags (const vfs_path_t * vpath);
|
vfs_class_flags_t vfs_file_class_flags (const vfs_path_t * vpath);
|
||||||
|
|
||||||
/* translate path back to terminal encoding, remove all #enc:
|
/* translate path back to terminal encoding, remove all #enc:
|
||||||
|
@ -234,17 +234,22 @@ free_linklist (struct link **lc_linklist)
|
|||||||
static int
|
static int
|
||||||
is_in_linklist (struct link *lp, const char *path, struct stat *sb)
|
is_in_linklist (struct link *lp, const char *path, struct stat *sb)
|
||||||
{
|
{
|
||||||
|
vfs_path_t *vpath;
|
||||||
|
vfs_path_element_t *vpath_element;
|
||||||
ino_t ino = sb->st_ino;
|
ino_t ino = sb->st_ino;
|
||||||
dev_t dev = sb->st_dev;
|
dev_t dev = sb->st_dev;
|
||||||
struct vfs_class *vfs = vfs_get_class (path);
|
|
||||||
|
vpath = vfs_path_from_str (path);
|
||||||
|
vpath_element = vfs_path_get_by_index (vpath, -1);
|
||||||
|
|
||||||
while (lp != NULL)
|
while (lp != NULL)
|
||||||
{
|
{
|
||||||
if (lp->vfs == vfs)
|
if (lp->vfs == vpath_element->class)
|
||||||
if (lp->ino == ino && lp->dev == dev)
|
if (lp->ino == ino && lp->dev == dev)
|
||||||
return 1;
|
return 1;
|
||||||
lp = lp->next;
|
lp = lp->next;
|
||||||
}
|
}
|
||||||
|
vfs_path_free (vpath);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,12 +286,29 @@ check_hardlinks (const char *src_name, const char *dst_name, struct stat *pstat)
|
|||||||
for (lp = linklist; lp != NULL; lp = lp->next)
|
for (lp = linklist; lp != NULL; lp = lp->next)
|
||||||
if (lp->vfs == my_vfs && lp->ino == ino && lp->dev == dev)
|
if (lp->vfs == my_vfs && lp->ino == ino && lp->dev == dev)
|
||||||
{
|
{
|
||||||
|
struct vfs_class *lp_name_class;
|
||||||
|
|
||||||
|
vpath = vfs_path_from_str (lp->name);
|
||||||
|
lp_name_class = vfs_path_get_by_index (vpath, -1)->class;
|
||||||
|
vfs_path_free (vpath);
|
||||||
|
|
||||||
if (!mc_stat (lp->name, &link_stat) && link_stat.st_ino == ino
|
if (!mc_stat (lp->name, &link_stat) && link_stat.st_ino == ino
|
||||||
&& link_stat.st_dev == dev && vfs_get_class (lp->name) == my_vfs)
|
&& link_stat.st_dev == dev && lp_name_class == my_vfs)
|
||||||
{
|
{
|
||||||
|
struct vfs_class *p_class, *dst_name_class;
|
||||||
|
|
||||||
p = strchr (lp->name, 0) + 1; /* i.e. where the `name' file
|
p = strchr (lp->name, 0) + 1; /* i.e. where the `name' file
|
||||||
was copied to */
|
was copied to */
|
||||||
if (vfs_get_class (dst_name) == vfs_get_class (p))
|
|
||||||
|
vpath = vfs_path_from_str (p);
|
||||||
|
p_class = vfs_path_get_by_index (vpath, -1)->class;
|
||||||
|
vfs_path_free (vpath);
|
||||||
|
|
||||||
|
vpath = vfs_path_from_str (dst_name);
|
||||||
|
dst_name_class = vfs_path_get_by_index (vpath, -1)->class;
|
||||||
|
vfs_path_free (vpath);
|
||||||
|
|
||||||
|
if (dst_name_class == p_class)
|
||||||
{
|
{
|
||||||
if (!mc_stat (p, &link_stat))
|
if (!mc_stat (p, &link_stat))
|
||||||
{
|
{
|
||||||
@ -1754,7 +1776,11 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
lp = g_new (struct link, 1);
|
lp = g_new (struct link, 1);
|
||||||
lp->vfs = vfs_get_class (s);
|
{
|
||||||
|
vfs_path_t *vpath = vfs_path_from_str (s);
|
||||||
|
lp->vfs = vfs_path_get_by_index (vpath, -1)->class;
|
||||||
|
vfs_path_free (vpath);
|
||||||
|
}
|
||||||
lp->ino = cbuf.st_ino;
|
lp->ino = cbuf.st_ino;
|
||||||
lp->dev = cbuf.st_dev;
|
lp->dev = cbuf.st_dev;
|
||||||
lp->next = parent_dirs;
|
lp->next = parent_dirs;
|
||||||
@ -1814,7 +1840,11 @@ copy_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, con
|
|||||||
|
|
||||||
lp = g_new (struct link, 1);
|
lp = g_new (struct link, 1);
|
||||||
mc_stat (dest_dir, &buf);
|
mc_stat (dest_dir, &buf);
|
||||||
lp->vfs = vfs_get_class (dest_dir);
|
{
|
||||||
|
vfs_path_t *vpath = vfs_path_from_str (dest_dir);
|
||||||
|
lp->vfs = vfs_path_get_by_index (vpath, -1)->class;
|
||||||
|
vfs_path_free (vpath);
|
||||||
|
}
|
||||||
lp->ino = buf.st_ino;
|
lp->ino = buf.st_ino;
|
||||||
lp->dev = buf.st_dev;
|
lp->dev = buf.st_dev;
|
||||||
lp->next = dest_dirs;
|
lp->next = dest_dirs;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user