static void tree_move (WTree *tree, const char *default_dest) { char msg [BUF_MEDIUM]; char *dest; struct stat buf; double bytes = 0; off_t count = 0; FileOpContext *ctx; if (tree->selected_ptr == NULL) return; g_snprintf (msg, sizeof (msg), _("Move \"%s\" directory to:"), str_trunc (tree->selected_ptr->name, 50)); dest = input_expand_dialog (_(" Move "), msg, MC_HISTORY_FM_TREE_MOVE, default_dest); if (dest == NULL || *dest == '\0') { g_free (dest); return; } if (stat (dest, &buf)){ message (D_ERROR, MSG_ERROR, _(" Cannot stat the destination \n %s "), unix_error_string (errno)); g_free (dest); return; } if (!S_ISDIR (buf.st_mode)){ file_error (_(" Destination \"%s\" must be a directory \n %s "), dest); g_free (dest); return; } ctx = file_op_context_new (OP_MOVE); file_op_context_create_ui (ctx, FALSE); move_dir_dir (ctx, tree->selected_ptr->name, dest, &count, &bytes); file_op_context_destroy (ctx); g_free (dest); }
void mkdir_cmd (void) { char *dir, *absdir; const char *name = ""; /* If 'on' then automatically fills name with current selected item name */ if (auto_fill_mkdir_name && strcmp (selection (current_panel)->fname, "..") != 0) name = selection (current_panel)->fname; dir = input_expand_dialog (_("Create a new Directory"), _("Enter directory name:"), MC_HISTORY_FM_MKDIR, name); if (!dir) return; if (*dir) { if (dir[0] == '/' || dir[0] == '~') absdir = g_strdup (dir); else absdir = concat_dir_and_file (current_panel->cwd, dir); 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)); } g_free (absdir); } g_free (dir); }
void edit_symlink_cmd (void) { if (S_ISLNK (selection (current_panel)->st.st_mode)) { char buffer [MC_MAXPATHLEN]; char *p = NULL; int i; char *dest, *q; p = selection (current_panel)->fname; q = g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p, 32)); i = readlink (p, buffer, MC_MAXPATHLEN - 1); if (i > 0) { buffer [i] = 0; dest = input_expand_dialog (_(" Edit symlink "), q, buffer); if (dest) { if (*dest && strcmp (buffer, dest)) { save_cwds_stat (); if (-1 == mc_unlink (p)){ message (1, MSG_ERROR, _(" edit symlink, unable to remove %s: %s "), p, unix_error_string (errno)); } else { if (-1 == mc_symlink (dest, p)) message (1, MSG_ERROR, _(" edit symlink: %s "), unix_error_string (errno)); } update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); } g_free (dest); } } g_free (q); } else { message (1, MSG_ERROR, _("`%s' is not a symbolic link"), selection (current_panel)->fname); } }
static void do_link (link_type_t link_type, const char *fname) { char *dest = NULL, *src = NULL; vfs_path_t *fname_vpath, *dest_vpath = NULL; fname_vpath = vfs_path_from_str (fname); if (link_type == LINK_HARDLINK) { src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46)); dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, "", INPUT_COMPLETE_FILENAMES); if (!dest || !*dest) goto cleanup; save_cwds_stat (); dest_vpath = vfs_path_from_str (dest); if (-1 == mc_link (fname_vpath, dest_vpath)) message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno)); } else { vfs_path_t *s, *d; /* suggest the full path for symlink, and either the full or relative path to the file it points to */ s = vfs_path_append_new (current_panel->cwd_vpath, fname, NULL); if (get_other_type () == view_listing) d = vfs_path_append_new (other_panel->cwd_vpath, fname, NULL); else d = vfs_path_from_str (fname); if (link_type == LINK_SYMLINK_RELATIVE) { char *s_str; s_str = diff_two_paths (other_panel->cwd_vpath, s); vfs_path_free (s); s = vfs_path_from_str_flags (s_str, VPF_NO_CANON); g_free (s_str); } symlink_dialog (s, d, &dest, &src); vfs_path_free (d); vfs_path_free (s); if (!dest || !*dest || !src || !*src) goto cleanup; save_cwds_stat (); dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON); s = vfs_path_from_str (src); if (mc_symlink (dest_vpath, s) == -1) message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno)); vfs_path_free (s); } update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); cleanup: vfs_path_free (fname_vpath); vfs_path_free (dest_vpath); g_free (src); g_free (dest); }