Пример #1
0
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);
}
Пример #2
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* */
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);

}
Пример #4
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);
    }
}
Пример #5
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);
}
Пример #6
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();
}
/* *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);
}
Пример #8
0
Файл: chmod.c Проект: 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);
}
Пример #9
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);
}
Пример #10
0
int
invoke_subshell (const char *command, int how, vfs_path_t ** new_dir_vpath)
{
    char *pcwd;

    /* Make the MC terminal transparent */
    tcsetattr (STDOUT_FILENO, TCSANOW, &raw_mode);

    /* Make the subshell change to MC's working directory */
    if (new_dir_vpath != NULL)
        do_subshell_chdir (current_panel->cwd_vpath, TRUE, TRUE);

    if (command == NULL)        /* The user has done "C-o" from MC */
    {
        if (subshell_state == INACTIVE)
        {
            subshell_state = ACTIVE;
            /* FIXME: possibly take out this hack; the user can
               re-play it by hitting C-hyphen a few times! */
            if (subshell_ready)
                write_all (mc_global.tty.subshell_pty, " \b", 2);       /* Hack to make prompt reappear */
        }
    }
    else                        /* MC has passed us a user command */
    {
        if (how == QUIETLY)
            write_all (mc_global.tty.subshell_pty, " ", 1);
        /* FIXME: if command is long (>8KB ?) we go comma */
        write_all (mc_global.tty.subshell_pty, command, strlen (command));
        write_all (mc_global.tty.subshell_pty, "\n", 1);
        subshell_state = RUNNING_COMMAND;
        subshell_ready = FALSE;
    }

    feed_subshell (how, FALSE);

    {
        char *cwd_str;

        cwd_str = vfs_path_to_str (current_panel->cwd_vpath);
        pcwd = vfs_translate_path_n (cwd_str);
        g_free (cwd_str);
    }

    if (new_dir_vpath != NULL && subshell_alive && strcmp (subshell_cwd, pcwd))
        *new_dir_vpath = vfs_path_from_str (subshell_cwd);      /* Make MC change to the subshell's CWD */
    g_free (pcwd);

    /* Restart the subshell if it has died by SIGHUP, SIGQUIT, etc. */
    while (!subshell_alive && quit == 0 && mc_global.tty.use_subshell)
        init_subshell ();

    prompt_pos = 0;

    return quit;
}
Пример #11
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);
}
Пример #12
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);
}
Пример #13
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);
}
Пример #14
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_vfs_path_append_vpath, test_vfs_path_append_vpath_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath1, *vpath2, *vpath3;

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

    /* when */
    vpath3 = vfs_path_append_vpath_new (vpath1, vpath2, NULL);

    /* then */
    mctest_assert_int_eq (vfs_path_elements_count (vpath3), data->expected_element_count);
    mctest_assert_str_eq (vfs_path_as_str (vpath3), data->expected_path);

    vfs_path_free (vpath1);
    vfs_path_free (vpath2);
    vfs_path_free (vpath3);
}
Пример #15
0
static char *
sftpfs_correct_file_name (const char *filename)
{
    vfs_path_t *vpath;
    char *ret_value;

    vpath = vfs_path_from_str (filename);
    ret_value = vfs_path_to_str (vpath);
    vfs_path_free (vpath);
    return ret_value;
}
Пример #16
0
static void
load_tree (WTree * tree)
{
    vfs_path_t *vpath;

    tree_store_load ();

    tree->selected_ptr = tree->store->tree_first;
    vpath = vfs_path_from_str (mc_config_get_home_dir ());
    tree_chdir (tree, vpath);
    vfs_path_free (vpath);
}
Пример #17
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);
}
Пример #18
0
static char *
sftpfs_correct_file_name (const char *filename)
{
    vfs_path_t *vpath;
    char *ret_value;

    ret_value = tilde_expand (filename);
    vpath = vfs_path_from_str (ret_value);
    g_free (ret_value);
    ret_value = g_strdup (vfs_path_as_str (vpath));
    vfs_path_free (vpath);
    return ret_value;
}
Пример #19
0
Файл: chown.c Проект: LubkaB/mc
static void
do_chown (uid_t u, gid_t g)
{
    vfs_path_t *vpath;

    vpath = vfs_path_from_str (current_panel->dir.list[current_file].fname);
    if (mc_chown (vpath, u, g) == -1)
        message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                 current_panel->dir.list[current_file].fname, unix_error_string (errno));

    vfs_path_free (vpath);
    do_file_mark (current_panel, current_file, 0);
}
Пример #20
0
Файл: dir.c Проект: Chainie/mc
static int
handle_dirent (dir_list * list, const char *fltr, struct dirent *dp,
               struct stat *buf1, int next_free, int *link_to_dir, int *stale_link)
{
    vfs_path_t *vpath;

    if (dp->d_name[0] == '.' && dp->d_name[1] == 0)
        return 0;
    if (dp->d_name[0] == '.' && dp->d_name[1] == '.' && dp->d_name[2] == 0)
        return 0;
    if (!panels_options.show_dot_files && (dp->d_name[0] == '.'))
        return 0;
    if (!panels_options.show_backups && dp->d_name[NLENGTH (dp) - 1] == '~')
        return 0;

    vpath = vfs_path_from_str (dp->d_name);
    if (mc_lstat (vpath, buf1) == -1)
    {
        /*
         * lstat() fails - such entries should be identified by
         * buf1->st_mode being 0.
         * It happens on QNX Neutrino for /fs/cd0 if no CD is inserted.
         */
        memset (buf1, 0, sizeof (*buf1));
    }

    if (S_ISDIR (buf1->st_mode))
        tree_store_mark_checked (dp->d_name);

    /* 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);
    if (!(S_ISDIR (buf1->st_mode) || *link_to_dir) && (fltr != NULL)
        && !mc_search (fltr, dp->d_name, MC_SEARCH_T_GLOB))
        return 0;

    /* Need to grow the *list? */
    if (next_free == list->size && !grow_list (list))
        return -1;

    return 1;
}
Пример #21
0
static gboolean
mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, GError ** mcerror)
{
    gchar *data, *written_data;
    gsize len, total_written;
    gboolean ret;
    int fd;
    ssize_t cur_written;
    vfs_path_t *ini_vpath;

    mc_return_val_if_error (mcerror, FALSE);

    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, mcerror);
        g_free (data);
        return ret;
    }

    mc_util_make_backup_if_possible (ini_path, "~");

    ini_vpath = vfs_path_from_str (ini_path);
    fd = mc_open (ini_vpath, O_WRONLY | O_TRUNC, 0);
    vfs_path_free (ini_vpath);

    if (fd == -1)
    {
        mc_propagate_error (mcerror, 0, "%s", unix_error_string (errno));
        g_free (data);
        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, "~");
        mc_propagate_error (mcerror, 0, "%s", unix_error_string (errno));
        return FALSE;
    }

    mc_util_unlink_backup_if_possible (ini_path, "~");
    return TRUE;
}
Пример #22
0
void
tree_chdir (WTree * tree, const char *dir)
{
    vfs_path_t *vpath;
    tree_entry *current;

    vpath = vfs_path_from_str (dir);
    current = tree_store_whereis (vpath);
    if (current != NULL)
    {
        tree->selected_ptr = current;
        tree_check_focus (tree);
    }
    vfs_path_free (vpath);
}
Пример #23
0
Файл: chmod.c Проект: BrEacK/mc
static void
do_chmod (struct stat *sf)
{
    vfs_path_t *vpath;
    sf->st_mode &= and_mask;
    sf->st_mode |= or_mask;

    vpath = vfs_path_from_str (current_panel->dir.list[c_file].fname);
    if (mc_chmod (vpath, sf->st_mode) == -1)
        message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
                 current_panel->dir.list[c_file].fname, unix_error_string (errno));

    vfs_path_free (vpath);
    do_file_mark (current_panel, c_file, 0);
}
Пример #24
0
void
mkdir_cmd (void)
{
    char *dir;
    const char *name = "";

    /* If 'on' then automatically fills name with current selected item name */
    if (auto_fill_mkdir_name && !DIR_IS_DOTDOT (selection (current_panel)->fname))
        name = selection (current_panel)->fname;

    dir =
        input_expand_dialog (_("Create a new Directory"),
                             _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name,
                             INPUT_COMPLETE_FILENAMES);

    if (dir != NULL && *dir != '\0')
    {
        vfs_path_t *absdir;

        if (dir[0] == '/' || dir[0] == '~')
            absdir = vfs_path_from_str (dir);
        else
        {
            /* possible escaped '~' */
            /* allow create directory with name '~' */
            char *tmpdir = dir;

            if (dir[0] == '\\' && dir[1] == '~')
                tmpdir = dir + 1;

            absdir = vfs_path_append_new (current_panel->cwd_vpath, tmpdir, NULL);
        }

        save_cwds_stat ();
        if (my_mkdir (absdir, 0777) == 0)
        {
            update_panels (UP_OPTIMIZE, dir);
            repaint_screen ();
            select_item (current_panel);
        }
        else
        {
            message (D_ERROR, MSG_ERROR, "%s", unix_error_string (errno));
        }
        vfs_path_free (absdir);
    }
    g_free (dir);
}
Пример #25
0
static void
tree_move (WTree * tree, const char *default_dest)
{
    char msg[BUF_MEDIUM];
    char *dest;
    struct stat buf;
    file_op_context_t *ctx;
    file_op_total_context_t *tctx;
    vfs_path_t *dest_vpath = NULL;

    if (tree->selected_ptr == NULL)
        return;

    g_snprintf (msg, sizeof (msg), _("Move \"%s\" directory to:"),
                str_trunc (vfs_path_as_str (tree->selected_ptr->name), 50));
    dest =
        input_expand_dialog (Q_ ("DialogTitle|Move"), msg, MC_HISTORY_FM_TREE_MOVE, default_dest,
                             INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD);

    if (dest == NULL || *dest == '\0')
        goto ret;

    dest_vpath = vfs_path_from_str (dest);

    if (mc_stat (dest_vpath, &buf))
    {
        message (D_ERROR, MSG_ERROR, _("Cannot stat the destination\n%s"),
                 unix_error_string (errno));
        goto ret;
    }

    if (!S_ISDIR (buf.st_mode))
    {
        file_error (_("Destination \"%s\" must be a directory\n%s"), dest);
        goto ret;
    }

    ctx = file_op_context_new (OP_MOVE);
    tctx = file_op_total_context_new ();
    file_op_context_create_ui (ctx, FALSE, FILEGUI_DIALOG_ONE_ITEM);
    move_dir_dir (tctx, ctx, vfs_path_as_str (tree->selected_ptr->name), dest);
    file_op_total_context_destroy (tctx);
    file_op_context_destroy (ctx);

  ret:
    vfs_path_free (dest_vpath);
    g_free (dest);
}
static void
setup (void)
{
    str_init_strings (NULL);

    vfs_init ();
    init_localfs ();
    vfs_setup_work_dir ();

    mc_global.mc_run_mode = MC_RUN_FULL;
    current_panel = g_new0 (WPanel, 1);
    current_panel->cwd_vpath = vfs_path_from_str ("/home");
    current_panel->dir.size = DIR_LIST_MIN_SIZE;
    current_panel->dir.list = g_new0 (file_entry_t, current_panel->dir.size);
    current_panel->dir.len = 0;
}
Пример #27
0
void
vfs_list (void)
{
    char *target;
    vfs_path_t *target_vpath;

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

    target_vpath = vfs_path_from_str (target);
    if (!do_cd (target_vpath, cd_exact))
        message (D_ERROR, MSG_ERROR, _("Cannot change directory"));
    vfs_path_free (target_vpath);
    g_free (target);
}
Пример #28
0
Файл: util.c Проект: JBurant/mc
const char *
path_trunc (const char *path, size_t trunc_len)
{
    vfs_path_t *vpath;
    char *secure_path;
    const char *ret;

    vpath = vfs_path_from_str (path);
    secure_path = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD);
    vfs_path_free (vpath);

    ret = str_trunc (secure_path, trunc_len);
    g_free (secure_path);

    return ret;
}
Пример #29
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_path_length, test_path_length_ds)
/* *INDENT-ON* */
{
    /* given */
    vfs_path_t *vpath;
    size_t actual_length;

    vpath = vfs_path_from_str (data->input_path);

    /* when */
    actual_length = vfs_path_len (vpath);

    /* then */
    mctest_assert_int_eq (actual_length, data->expected_length);

    vfs_path_free (vpath);
}
Пример #30
0
static gboolean
handle_dirent (struct dirent *dp, const char *fltr, struct stat *buf1, int *link_to_dir,
               int *stale_link)
{
    vfs_path_t *vpath;

    if (DIR_IS_DOT (dp->d_name) || DIR_IS_DOTDOT (dp->d_name))
        return FALSE;
    if (!panels_options.show_dot_files && (dp->d_name[0] == '.'))
        return FALSE;
    if (!panels_options.show_backups && dp->d_name[strlen (dp->d_name) - 1] == '~')
        return FALSE;

    vpath = vfs_path_from_str (dp->d_name);
    if (mc_lstat (vpath, buf1) == -1)
    {
        /*
         * lstat() fails - such entries should be identified by
         * buf1->st_mode being 0.
         * It happens on QNX Neutrino for /fs/cd0 if no CD is inserted.
         */
        memset (buf1, 0, sizeof (*buf1));
    }

    if (S_ISDIR (buf1->st_mode))
        tree_store_mark_checked (dp->d_name);

    /* 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 (S_ISDIR (buf1->st_mode) || *link_to_dir != 0 || fltr == NULL
            || mc_search (fltr, NULL, dp->d_name, MC_SEARCH_T_GLOB));
}