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); } }
static void do_link (link_type_t link_type, const char *fname) { char *dest = NULL, *src = NULL; 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, ""); if (!dest || !*dest) goto cleanup; save_cwds_stat (); if (-1 == mc_link (fname, dest)) message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno)); } else { char *s; char *d; /* suggest the full path for symlink, and either the full or relative path to the file it points to */ s = concat_dir_and_file (current_panel->cwd, fname); if (get_other_type () == view_listing) d = concat_dir_and_file (other_panel->cwd, fname); else d = g_strdup (fname); if (link_type == LINK_SYMLINK_RELATIVE) s = diff_two_paths (other_panel->cwd, s); symlink_dialog (s, d, &dest, &src); g_free (d); g_free (s); if (!dest || !*dest || !src || !*src) goto cleanup; save_cwds_stat (); if (-1 == mc_symlink (dest, src)) message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno)); } update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); cleanup: g_free (src); g_free (dest); }
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:"), str_trunc (p, 32)); i = readlink (p, buffer, MC_MAXPATHLEN - 1); if (i > 0) { buffer[i] = 0; dest = input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer); if (dest) { if (*dest && strcmp (buffer, dest)) { save_cwds_stat (); if (-1 == mc_unlink (p)) { message (D_ERROR, MSG_ERROR, _("edit symlink, unable to remove %s: %s"), p, unix_error_string (errno)); } else { if (-1 == mc_symlink (dest, p)) message (D_ERROR, 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 (D_ERROR, MSG_ERROR, _("`%s' is not a symbolic link"), selection (current_panel)->fname); } }
static void do_link (int symbolic_link, const char *fname) { char *dest = NULL, *src = NULL; if (!symbolic_link) { src = g_strdup_printf (_("Link %s to:"), name_trunc (fname, 46)); dest = input_expand_dialog (_(" Link "), src, ""); if (!dest || !*dest) goto cleanup; save_cwds_stat (); if (-1 == mc_link (fname, dest)) message (1, MSG_ERROR, _(" link: %s "), unix_error_string (errno)); } else { char *s; char *d; /* suggest the full path for symlink */ s = concat_dir_and_file (current_panel->cwd, fname); if (get_other_type () == view_listing) { d = concat_dir_and_file (other_panel->cwd, fname); } else { d = g_strdup (fname); } symlink_dialog (s, d, &dest, &src); g_free (d); g_free (s); if (!dest || !*dest || !src || !*src) goto cleanup; save_cwds_stat (); if (-1 == mc_symlink (dest, src)) message (1, MSG_ERROR, _(" symlink: %s "), unix_error_string (errno)); } update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); cleanup: g_free (src); g_free (dest); }
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); }