Exemplo n.º 1
0
Arquivo: lib.c Projeto: iNode/mc
void
mcview_done (mcview_t * view)
{
    /* Save current file position */
    if (mcview_remember_file_position && view->filename_vpath != NULL)
    {
        save_file_position (view->filename_vpath, -1, 0,
                            view->hex_mode ? view->hex_cursor : view->dpy_start,
                            view->saved_bookmarks);
        view->saved_bookmarks = NULL;
    }

    /* Write back the global viewer mode */
    mcview_default_hex_mode = view->hex_mode;
    mcview_default_nroff_flag = view->text_nroff_mode;
    mcview_default_magic_flag = view->magic_mode;
    mcview_global_wrap_mode = view->text_wrap_mode;

    /* Free memory used by the viewer */

    /* view->widget needs no destructor */

    vfs_path_free (view->filename_vpath);
    view->filename_vpath = NULL;
    vfs_path_free (view->workdir_vpath);
    view->workdir_vpath = NULL;
    MC_PTR_FREE (view->command);

    mcview_close_datasource (view);
    /* the growing buffer is freed with the datasource */

    coord_cache_free (view->coord_cache), view->coord_cache = NULL;

    if (view->converter == INVALID_CONV)
        view->converter = str_cnv_from_term;

    if (view->converter != str_cnv_from_term)
    {
        str_close_conv (view->converter);
        view->converter = str_cnv_from_term;
    }

    mc_search_free (view->search);
    view->search = NULL;
    g_free (view->last_search_string);
    view->last_search_string = NULL;
    mcview_nroff_seq_free (&view->search_nroff_seq);
    mcview_hexedit_free_change_list (view);

    if (mc_global.mc_run_mode == MC_RUN_VIEWER && view->dir != NULL)
    {
        /* mcviewer is the owner of file list */
        dir_list_clean (view->dir);
        g_free (view->dir->list);
        g_free (view->dir_idx);
        g_free (view->dir);
    }

    view->dir = NULL;
}
Exemplo n.º 2
0
/* *INDENT-OFF* */
END_PARAMETRIZED_TEST
/* *INDENT-ON* */

/* --------------------------------------------------------------------------------------------- */

/* @Test(dataSource = "test_vfs_path_relative_ds") */
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_vfs_path_relative_clone, test_vfs_path_relative_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath, *cloned_vpath;

    vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON);

    /* when */

    cloned_vpath = vfs_path_clone (vpath);

    /* then */
    mctest_assert_int_eq (cloned_vpath->relative, TRUE);
    mctest_assert_str_eq (vfs_path_get_last_path_str (cloned_vpath),
                          data->expected_last_path_in_element);
    mctest_assert_str_eq (vfs_path_as_str (cloned_vpath), data->expected_path);

    vfs_path_free (vpath);
    vfs_path_free (cloned_vpath);
}
Exemplo n.º 3
0
void
edit_symlink_cmd (void)
{
    if (S_ISLNK (selection (current_panel)->st.st_mode))
    {
        char buffer[MC_MAXPATHLEN];
        char *p = NULL;
        int i;
        char *q;
        vfs_path_t *p_vpath;

        p = selection (current_panel)->fname;
        p_vpath = vfs_path_from_str (p);

        q = g_strdup_printf (_("Symlink '%s\' points to:"), str_trunc (p, 32));

        i = readlink (p, buffer, MC_MAXPATHLEN - 1);
        if (i > 0)
        {
            char *dest;

            buffer[i] = 0;
            dest =
                input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer,
                                     INPUT_COMPLETE_FILENAMES);
            if (dest)
            {
                if (*dest && strcmp (buffer, dest))
                {
                    save_cwds_stat ();
                    if (mc_unlink (p_vpath) == -1)
                    {
                        message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"),
                                 p, unix_error_string (errno));
                    }
                    else
                    {
                        vfs_path_t *dest_vpath;

                        dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
                        if (mc_symlink (dest_vpath, p_vpath) == -1)
                            message (D_ERROR, MSG_ERROR, _("edit symlink: %s"),
                                     unix_error_string (errno));
                        vfs_path_free (dest_vpath);
                    }
                    update_panels (UP_OPTIMIZE, UP_KEEPSEL);
                    repaint_screen ();
                }
                g_free (dest);
            }
        }
        g_free (q);
        vfs_path_free (p_vpath);
    }
    else
    {
        message (D_ERROR, MSG_ERROR, _("'%s' is not a symbolic link"),
                 selection (current_panel)->fname);
    }
}
Exemplo n.º 4
0
/**
 * Run viewer (internal or external) on the currently selected file.
 * If normal is TRUE, force internal viewer and raw mode (used for F13).
 */
static void
do_view_cmd (gboolean normal)
{
    /* Directories are viewed by changing to them */
    if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel)))
    {
        vfs_path_t *fname_vpath;

        if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked))
        {
            if (query_dialog
                (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2,
                 _("&Yes"), _("&No")) != 0)
            {
                return;
            }
        }
        fname_vpath = vfs_path_from_str (selection (current_panel)->fname);
        if (!do_cd (fname_vpath, cd_exact))
            message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
        vfs_path_free (fname_vpath);
    }
    else
    {
        int file_idx;
        vfs_path_t *filename_vpath;

        file_idx = current_panel->selected;
        filename_vpath = vfs_path_from_str (current_panel->dir.list[file_idx].fname);
        view_file (filename_vpath, normal, use_internal_view != 0);
        vfs_path_free (filename_vpath);
    }

    repaint_screen ();
}
Exemplo n.º 5
0
gboolean
handle_path (const char *path, struct stat * buf1, int *link_to_dir, int *stale_link)
{
    vfs_path_t *vpath;

    if (DIR_IS_DOT (path) || DIR_IS_DOTDOT (path))
        return FALSE;

    vpath = vfs_path_from_str (path);
    if (mc_lstat (vpath, buf1) == -1)
    {
        vfs_path_free (vpath);
        return FALSE;
    }

    if (S_ISDIR (buf1->st_mode))
        tree_store_mark_checked (path);

    /* A link to a file or a directory? */
    *link_to_dir = 0;
    *stale_link = 0;
    if (S_ISLNK (buf1->st_mode))
    {
        struct stat buf2;

        if (mc_stat (vpath, &buf2) == 0)
            *link_to_dir = S_ISDIR (buf2.st_mode) != 0;
        else
            *stale_link = 1;
    }

    vfs_path_free (vpath);

    return TRUE;
}
/* *INDENT-OFF* */
END_TEST
/* *INDENT-ON* */

/* --------------------------------------------------------------------------------------------- */

/* @Test */
/* *INDENT-OFF* */
START_TEST (the_file_is_remote)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *filename_vpath, *local_vpath, *local_vpath_should_be_freeing;

    filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt");
    local_vpath = vfs_path_from_str ("/tmp/blabla-editme.txt");
    local_vpath_should_be_freeing = vfs_path_clone (local_vpath);

    vfs_file_is_local__return_value = FALSE;
    mc_getlocalcopy__return_value = local_vpath_should_be_freeing;

    /* when */
    execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);

    /* then */
    mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_remote_file");
    mctest_assert_str_eq (do_execute__command__captured, "/tmp/blabla-editme.txt");

    mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);

    mctest_assert_int_eq (vfs_path_equal
                          (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
                           filename_vpath), TRUE);

    mctest_assert_int_eq (vfs_path_equal
                          (mc_getlocalcopy__pathname_vpath__captured, filename_vpath), TRUE);

    mctest_assert_int_eq (mc_stat__vpath__captured->len, 2);

    mctest_assert_int_eq (vfs_path_equal
                          (g_ptr_array_index (mc_stat__vpath__captured, 0), local_vpath), TRUE);
    mctest_assert_int_eq (vfs_path_equal
                          (g_ptr_array_index (mc_stat__vpath__captured, 0),
                           g_ptr_array_index (mc_stat__vpath__captured, 1)), TRUE);

    mctest_assert_int_eq (vfs_path_equal
                          (mc_ungetlocalcopy__pathname_vpath__captured, filename_vpath), TRUE);

    mctest_assert_int_eq (vfs_path_equal (mc_ungetlocalcopy__local_vpath__captured, local_vpath),
                          TRUE);

    vfs_path_free (filename_vpath);
    vfs_path_free (local_vpath);
}
Exemplo n.º 7
0
void
edit_mc_menu_cmd (void)
{
    vfs_path_t *buffer_vpath;
    vfs_path_t *menufile_vpath;
    int dir = 0;

    query_set_sel (1);
    dir = query_dialog (_("Menu edit"),
                        _("Which menu file do you want to edit?"),
                        D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide"));

    menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);

    if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
    {
        vfs_path_free (menufile_vpath);
        menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
    }

    switch (dir)
    {
    case 0:
        buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
        check_for_default (menufile_vpath, buffer_vpath);
        chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
        break;

    case 1:
        buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
        check_for_default (menufile_vpath, buffer_vpath);
        break;

    case 2:
        buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL);
        if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
        {
            vfs_path_free (buffer_vpath);
            buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL);
        }
        break;

    default:
        vfs_path_free (menufile_vpath);
        return;
    }

    do_edit (buffer_vpath);

    vfs_path_free (buffer_vpath);
    vfs_path_free (menufile_vpath);
}
Exemplo n.º 8
0
Arquivo: achown.c Projeto: jskDr/mc
static void
apply_advanced_chowns (struct stat *sf)
{
    vfs_path_t *vpath;
    char *lc_fname;
    gid_t a_gid = sf->st_gid;
    uid_t a_uid = sf->st_uid;

    lc_fname = current_panel->dir.list[current_file].fname;
    vpath = vfs_path_from_str (lc_fname);
    need_update = end_chown = TRUE;
    if (mc_chmod (vpath, get_mode ()) == -1)
        message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
                 lc_fname, unix_error_string (errno));
    /* call mc_chown only, if mc_chmod didn't fail */
    else if (mc_chown (vpath, (ch_flags[9] == '+') ? sf->st_uid : (uid_t) (-1),
                       (ch_flags[10] == '+') ? sf->st_gid : (gid_t) (-1)) == -1)
        message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                 lc_fname, unix_error_string (errno));
    do_file_mark (current_panel, current_file, 0);
    vfs_path_free (vpath);

    do
    {
        lc_fname = next_file ();
        vpath = vfs_path_from_str (lc_fname);

        if (mc_stat (vpath, sf) != 0)
        {
            vfs_path_free (vpath);
            break;
        }

        ch_cmode = sf->st_mode;

        if (mc_chmod (vpath, get_mode ()) == -1)
            message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
                     lc_fname, unix_error_string (errno));
        /* call mc_chown only, if mc_chmod didn't fail */
        else if (mc_chown (vpath, (ch_flags[9] == '+') ? a_uid : (uid_t) (-1),
                           (ch_flags[10] == '+') ? a_gid : (gid_t) (-1)) == -1)
            message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                     lc_fname, unix_error_string (errno));

        do_file_mark (current_panel, current_file, 0);
        vfs_path_free (vpath);
    }
    while (current_panel->marked != 0);
}
Exemplo n.º 9
0
Arquivo: common.c Projeto: Chainie/mc
static gboolean
mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, GError ** error)
{
    gchar *data, *written_data;
    gsize len, total_written;
    gboolean ret;
    int fd;
    ssize_t cur_written;
    vfs_path_t *ini_vpath;

    ini_vpath = vfs_path_from_str (ini_path);
    data = g_key_file_to_data (mc_config->handle, &len, NULL);
    if (!exist_file (ini_path))
    {
        ret = g_file_set_contents (ini_path, data, len, error);
        g_free (data);
        vfs_path_free (ini_vpath);
        return ret;
    }
    mc_util_make_backup_if_possible (ini_path, "~");

    fd = mc_open (ini_vpath, O_WRONLY | O_TRUNC, 0);
    if (fd == -1)
    {
        g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno)));
        g_free (data);
        vfs_path_free (ini_vpath);
        return FALSE;
    }

    for (written_data = data, total_written = len;
         (cur_written = mc_write (fd, (const void *) written_data, total_written)) > 0;
         written_data += cur_written, total_written -= cur_written);
    mc_close (fd);
    g_free (data);

    if (cur_written == -1)
    {
        mc_util_restore_from_backup_if_possible (ini_path, "~");
        g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno)));
        vfs_path_free (ini_vpath);
        return FALSE;
    }

    mc_util_unlink_backup_if_possible (ini_path, "~");
    vfs_path_free (ini_vpath);
    return TRUE;
}
Exemplo n.º 10
0
/* event callback */
gboolean
clipboard_text_to_file (const gchar * event_group_name, const gchar * event_name,
                        gpointer init_data, gpointer data)
{
    int file;
    vfs_path_t *fname_vpath = NULL;
    size_t str_len;
    const char *text = (const char *) data;

    (void) event_group_name;
    (void) event_name;
    (void) init_data;

    if (text == NULL)
        return FALSE;

    fname_vpath = mc_config_get_full_vpath (EDIT_CLIP_FILE);
    file = mc_open (fname_vpath, O_CREAT | O_WRONLY | O_TRUNC,
                    S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY);
    vfs_path_free (fname_vpath);

    if (file == -1)
        return TRUE;

    str_len = strlen (text);
    {
        ssize_t ret;

        ret = mc_write (file, (char *) text, str_len);
        (void) ret;
    }
    mc_close (file);
    return TRUE;
}
Exemplo n.º 11
0
Arquivo: chmod.c Projeto: BrEacK/mc
static void
apply_mask (struct stat *sf)
{
    need_update = TRUE;
    end_chmod = TRUE;

    do_chmod (sf);

    do
    {
        char *fname;
        vfs_path_t *vpath;
        gboolean ok;

        fname = next_file ();
        vpath = vfs_path_from_str (fname);
        ok = (mc_stat (vpath, sf) == 0);
        vfs_path_free (vpath);
        if (!ok)
            return;

        c_stat = sf->st_mode;

        do_chmod (sf);
    }
    while (current_panel->marked != 0);
}
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (check_if_filename_and_lineno_will_be_subtituted, check_subtitute_ds)
/* *INDENT-ON* */
{
    /* given */
    char *actual_result;
    vfs_path_t *filename_vpath;

    g_ptr_array_add (mc_config_get_string__return_value, g_strdup (data->config_opts_string));
    filename_vpath = vfs_path_from_str (data->file_name);

    /* when */
    actual_result =
        execute_get_external_cmd_opts_from_config (data->app_name, filename_vpath,
                                                   data->start_line);

    /* then */

    /* check returned value */
    mctest_assert_str_eq (actual_result, data->expected_result);

    /* check calls to mc_config_get_string() function */
    mctest_assert_str_eq (g_ptr_array_index (mc_config_get_string__group__captured, 0),
                          CONFIG_EXT_EDITOR_VIEWER_SECTION);
    mctest_assert_str_eq (g_ptr_array_index (mc_config_get_string__param__captured, 0),
                          data->app_name);
    mctest_assert_str_eq (g_ptr_array_index (mc_config_get_string__default_value__captured, 0),
                          NULL);

    vfs_path_free (filename_vpath);

}
/* *INDENT-OFF* */
END_PARAMETRIZED_TEST
/* *INDENT-ON* */

/* --------------------------------------------------------------------------------------------- */

/* @Test */
/* *INDENT-OFF* */
START_TEST (the_file_is_remote_but_empty)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *filename_vpath;
    filename_vpath = NULL;

    vfs_file_is_local__return_value = FALSE;

    /* when */
    execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath);

    /* then */
    mctest_assert_str_eq (do_execute__lc_shell__captured, NULL);
    mctest_assert_str_eq (do_execute__command__captured, NULL);

    mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 2);

    mctest_assert_int_eq (vfs_path_equal
                          (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
                           vfs_get_raw_current_dir ()), TRUE);
    fail_unless (g_ptr_array_index (vfs_file_is_local__vpath__captured, 1) == NULL,
                 "\nParameter for second call to vfs_file_is_local() should be NULL!");
    fail_unless (mc_getlocalcopy__pathname_vpath__captured == NULL,
                 "\nFunction mc_getlocalcopy() shouldn't be called!");

    vfs_path_free (filename_vpath);
}
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (the_file_is_local, the_file_is_local_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *filename_vpath;
    filename_vpath = vfs_path_from_str (data->input_path);

    vfs_file_is_local__return_value = TRUE;

    /* when */
    execute_with_vfs_arg ("cmd_for_local_file", filename_vpath);

    /* then */
    mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_local_file");
    mctest_assert_str_eq (do_execute__command__captured, data->input_path);

    mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1);
    {
        const vfs_path_t *tmp_vpath;

        tmp_vpath = (data->input_path == NULL) ? vfs_get_raw_current_dir () : filename_vpath;
        mctest_assert_int_eq (vfs_path_equal
                              (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0),
                               tmp_vpath), TRUE);
    }
    mctest_assert_int_eq (do_execute__flags__captured, EXECUTE_INTERNAL);
    fail_unless (mc_getlocalcopy__pathname_vpath__captured == NULL,
                 "\nFunction mc_getlocalcopy() shouldn't be called!");

    vfs_path_free (filename_vpath);
}
Exemplo n.º 15
0
END_TEST
/* --------------------------------------------------------------------------------------------- */
#define ETALON_STR "/path/to/file.ext/test1://#enc:KOI8-R"
START_TEST (test_vfs_path_encoding_at_end)
{
    vfs_path_t *vpath;
    char *result;
    const vfs_path_element_t *element;

    mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
    load_codepages_list ();

    vpath = vfs_path_from_str_flags ("/path/to/file.ext#test1:/#enc:KOI8-R", VPF_USE_DEPRECATED_PARSER);
    result = vfs_path_to_str(vpath);

    element = vfs_path_get_by_index(vpath, -1);
    fail_unless(*element->path == '\0', "element->path should be empty, but actual value is '%s'",element->path);
    fail_unless(element->encoding != NULL && strcmp(element->encoding, "KOI8-R") == 0,
     "element->encoding should be 'KOI8-R', but actual value is '%s'",element->encoding);

    fail_unless( result != NULL && strcmp(result, ETALON_STR) ==0,
    "\nactual: %s\netalon: %s", result , ETALON_STR );

    g_free(result);
    vfs_path_free(vpath);

    free_codepages_list ();
}
Exemplo n.º 16
0
END_TEST

/* --------------------------------------------------------------------------------------------- */

START_TEST (test_vfs_path_from_to_string2)
{
    vfs_path_t *vpath;
    size_t vpath_len;
    char *result;
    const vfs_path_element_t *path_element;

    vpath = vfs_path_from_str ("/");

    vpath_len = vfs_path_elements_count(vpath);
    fail_unless(vpath_len == 1, "vpath length should be 1 (actial: %d)",vpath_len);

    result = vfs_path_to_str(vpath);
    fail_unless(strcmp("/", result) == 0, "expected(%s) doesn't equal to actual(%s)", "/", result);
    g_free(result);
    path_element = vfs_path_get_by_index (vpath, -1);
    fail_unless(strcmp("/", path_element->path) == 0, "expected(%s) doesn't equal to actual(%s)", "/", path_element->path);

    fail_unless(path_element->class == &vfs_local_ops , "actual vfs-class doesn't equal to localfs");

    vfs_path_free(vpath);
}
Exemplo n.º 17
0
void
hotlist_cmd (void)
{
    char *target;

    target = hotlist_show (LIST_HOTLIST);
    if (!target)
        return;

    if (get_current_type () == view_tree)
        tree_chdir (the_tree, target);
    else
    {
        vfs_path_t *deprecated_vpath;
        char *cmd;

        deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
        cmd = g_strconcat ("cd ", vfs_path_as_str (deprecated_vpath), (char *) NULL);
        vfs_path_free (deprecated_vpath);

        do_cd_command (cmd);
        g_free (cmd);
    }
    g_free (target);
}
Exemplo n.º 18
0
void
edit_cmd_new (void)
{
    vfs_path_t *fname_vpath = NULL;

    if (editor_ask_filename_before_edit)
    {
        char *fname;

        fname = input_expand_dialog (_("Edit file"), _("Enter file name:"),
                                     MC_HISTORY_EDIT_LOAD, "", INPUT_COMPLETE_FILENAMES);
        if (fname == NULL)
            return;

        if (*fname != '\0')
            fname_vpath = vfs_path_from_str (fname);

        g_free (fname);
    }

#ifdef HAVE_CHARSET
    mc_global.source_codepage = default_source_codepage;
#endif
    do_edit (fname_vpath);

    vfs_path_free (fname_vpath);
}
Exemplo n.º 19
0
static int
my_mkdir_rec (const vfs_path_t * s_vpath, mode_t mode)
{
    vfs_path_t *q;
    int result;

    if (mc_mkdir (s_vpath, mode) == 0)
        return 0;
    if (errno != ENOENT)
        return (-1);

    /* FIXME: should check instead if s_vpath is at the root of that filesystem */
    if (!vfs_file_is_local (s_vpath))
        return (-1);

    if (strcmp (vfs_path_as_str (s_vpath), PATH_SEP_STR) == 0)
    {
        errno = ENOTDIR;
        return (-1);
    }

    q = vfs_path_append_new (s_vpath, "..", NULL);
    result = my_mkdir_rec (q, mode);
    vfs_path_free (q);

    if (result == 0)
        result = mc_mkdir (s_vpath, mode);

    return result;
}
Exemplo n.º 20
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_to_str_flags, test_path_to_str_flags_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath;
    char *str_path;

    test_init_vfs ("UTF-8");

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

    /* when */

    vpath = vfs_path_from_str_flags (data->input_path, data->input_from_str_flags);
    str_path = vfs_path_to_str_flags (vpath, 0, data->input_to_str_flags);

    /* then */
    mctest_assert_str_eq (str_path, data->expected_path);

    g_free (str_path);
    vfs_path_free (vpath);
    test_deinit_vfs ();
}
Exemplo n.º 21
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_cd, test_cd_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath;

    vfs_test_ops.flags = data->input_class_flags;
    test_subclass.flags = data->input_subclass_flags;

    vfs_register_class (&vfs_test_ops);
    vfs_set_raw_current_dir (vfs_path_from_str (data->input_initial_path));

    vpath = vfs_path_from_str (data->input_cd_path);

    /* when */
    mc_chdir (vpath);

    /* then */
    {
        char *actual_cd_path;

        actual_cd_path = _vfs_get_cwd ();
        mctest_assert_str_eq (actual_cd_path, data->expected_cd_path);
        g_free (actual_cd_path);
    }
    vfs_path_free (vpath);
}
Exemplo n.º 22
0
END_TEST

/* --------------------------------------------------------------------------------------------- */

START_TEST(test_encode_info_at_start)
{
    vfs_path_t *vpath;
    char *actual;
    const vfs_path_element_t *vpath_element;

    test_init_vfs("UTF-8");

    vpath = vfs_path_from_str ("#enc:KOI8-R/bla-bla/some/path");
    actual = vfs_path_to_str (vpath);

    fail_unless (strcmp ("/#enc:KOI8-R/bla-bla/some/path", actual) == 0, "\nactual=%s\n", actual);

    vpath_element = vfs_path_get_by_index (vpath, -1);

    fail_unless (strcmp ("/bla-bla/some/path", vpath_element->path) == 0, "\nvpath_element->path=%s\n", vpath_element->path);

    g_free (actual);
    vfs_path_free (vpath);

    test_deinit_vfs();
}
Exemplo n.º 23
0
/* @After */
static void
teardown (void)
{
    vfs_path_free (do_cd__new_dir_vpath__captured);
    vfs_shut ();
    str_uninit_strings ();
}
Exemplo n.º 24
0
/* *INDENT-OFF* */
END_TEST
/* *INDENT-ON* */

/* --------------------------------------------------------------------------------------------- */

/* @Test */
/* *INDENT-OFF* */
START_TEST (test_mc_mkstemps)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *pname_vpath = NULL;
    char *pname = NULL;
    char *begin_pname;
    int fd;

    /* when */
    fd = mc_mkstemps (&pname_vpath, "mctest-", NULL);
    if (fd != -1)
        pname = vfs_path_to_str (pname_vpath);
    begin_pname = g_build_filename (mc_tmpdir (), "mctest-", NULL);

    /* then */
    vfs_path_free (pname_vpath);
    close (fd);
    mctest_assert_int_ne (fd, -1);
    fail_unless (g_file_test (pname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR),
                 "\nNo such file: %s\n", pname);
    unlink (pname);
    fail_unless (strncmp (pname, begin_pname, strlen (begin_pname)) == 0,
                 "\nstart of %s should be equal to %s\n", pname, begin_pname);
    g_free (pname);
}
Exemplo n.º 25
0
Arquivo: ext.c Projeto: inso/mc
static void
exec_cleanup_script (vfs_path_t * script_vpath)
{
    if (script_vpath != NULL)
    {
        (void) mc_unlink (script_vpath);
        vfs_path_free (script_vpath);
    }
}
Exemplo n.º 26
0
int
my_rmdir (const char *s)
{
    int result;
    vfs_path_t *vpath;

    vpath = vfs_path_from_str_flags (s, VPF_NO_CANON);
    /* FIXME: Should receive a Wtree! */
    result = mc_rmdir (vpath);
    if (result == 0)
    {
        vfs_path_t *my_s;

        my_s = get_absolute_name (vpath);
        vfs_path_free (my_s);
    }
    vfs_path_free (vpath);
    return result;
}
Exemplo n.º 27
0
Arquivo: actions_cmd.c Projeto: m32/mc
static void
mcview_remove_ext_script (mcview_t * view)
{
    if (view->ext_script != NULL)
    {
        mc_unlink (view->ext_script);
        vfs_path_free (view->ext_script);
        view->ext_script = NULL;
    }
}
Exemplo n.º 28
0
void
edit_cmd_force_internal (void)
{
    vfs_path_t *fname;

    fname = vfs_path_from_str (selection (current_panel)->fname);
    if (regex_command (fname, "Edit") == 0)
        edit_file_at_line (fname, TRUE, 1);
    vfs_path_free (fname);
}
Exemplo n.º 29
0
void
edit_cmd (void)
{
    vfs_path_t *fname;

    fname = vfs_path_from_str (selection (current_panel)->fname);
    if (regex_command (fname, "Edit") == 0)
        do_edit (fname);
    vfs_path_free (fname);
}
Exemplo n.º 30
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_equal_len, test_path_equal_len_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath1, *vpath2;
    gboolean actual_result;

    vpath1 = vfs_path_from_str (data->input_path1);
    vpath2 = vfs_path_from_str (data->input_path2);

    /* when */
    actual_result = vfs_path_equal_len (vpath1, vpath2, data->input_length);

    /* then */
    mctest_assert_int_eq (actual_result, data->expected_result);

    vfs_path_free (vpath1);
    vfs_path_free (vpath2);
}