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 (); }
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); } }
/* *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 (); }
/* *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); }
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); }
/* *INDENT-OFF* */ START_PARAMETRIZED_TEST (test_strip_home, test_strip_home_ds) /* *INDENT-ON* */ { /* given */ vfs_path_t *actual_result; /* when */ actual_result = vfs_path_from_str_flags (data->input_string, VPF_STRIP_HOME); /* then */ mctest_assert_str_eq (actual_result->str, data->expected_result); vfs_path_free (actual_result); }
void save_setup_cmd (void) { vfs_path_t *vpath; const char *path; vpath = vfs_path_from_str_flags (mc_config_get_path (), VPF_STRIP_HOME); path = vfs_path_as_str (vpath); if (save_setup (TRUE, TRUE)) message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path); else message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path); vfs_path_free (vpath); }
/* *INDENT-OFF* */ START_PARAMETRIZED_TEST (test_vfs_path_relative, test_vfs_path_relative_ds) /* *INDENT-ON* */ { /* given */ vfs_path_t *vpath; /* when */ vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON); /* then */ mctest_assert_int_eq (vpath->relative, TRUE); mctest_assert_str_eq (vfs_path_get_last_path_str (vpath), data->expected_last_path_in_element); mctest_assert_str_eq (vfs_path_as_str (vpath), data->expected_path); vfs_path_free (vpath); }
/* *INDENT-OFF* */ START_PARAMETRIZED_TEST (test_vfs_path_tokens_count, test_vfs_path_tokens_count_ds) /* *INDENT-ON* */ { /* given */ size_t tokens_count; vfs_path_t *vpath; vpath = vfs_path_from_str_flags (data->input_path, data->input_flags); /* when */ tokens_count = vfs_path_tokens_count (vpath); /* then */ mctest_assert_int_eq (tokens_count, data->expected_token_count); vfs_path_free (vpath); }
static void nice_cd (const char *text, const char *xtext, const char *help, const char *history_name, const char *prefix, int to_home, gboolean strip_password) { char *machine; char *cd_path; if (!SELECTED_IS_PANEL) return; machine = input_dialog_help (text, xtext, help, history_name, "", strip_password, INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD | INPUT_COMPLETE_HOSTNAMES | INPUT_COMPLETE_USERNAMES); if (machine == NULL) return; to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is ugly as hell and leads to problems in vfs layer */ if (strncmp (prefix, machine, strlen (prefix)) == 0) cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL); else cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL); g_free (machine); if (*cd_path != PATH_SEP) { char *tmp = cd_path; cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL); g_free (tmp); } { vfs_path_t *cd_vpath; cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON); if (!do_panel_cd (MENU_PANEL, cd_vpath, cd_parse_command)) message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); vfs_path_free (cd_vpath); } g_free (cd_path); }
/* *INDENT-OFF* */ START_PARAMETRIZED_TEST (test_vfs_path_tokens_get, test_vfs_path_tokens_get_ds) /* *INDENT-ON* */ { /* given */ vfs_path_t *vpath; char *actual_path; vpath = vfs_path_from_str_flags (data->input_path, VPF_NO_CANON); /* when */ actual_path = vfs_path_tokens_get (vpath, data->input_start_position, data->input_length); /* then */ mctest_assert_str_eq (actual_path, data->expected_path); g_free (actual_path); vfs_path_free (vpath); }
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; }
static void exec_extension_cd (void) { char *q; vfs_path_t *p_vpath; *pbuffer = '\0'; pbuffer = buffer; /* while (*p == ' ' && *p == '\t') * p++; */ /* Search last non-space character. Start search at the end in order not to short filenames containing spaces. */ q = pbuffer + strlen (pbuffer) - 1; while (q >= pbuffer && (*q == ' ' || *q == '\t')) q--; q[1] = 0; p_vpath = vfs_path_from_str_flags (pbuffer, VPF_NO_CANON); do_cd (p_vpath, cd_parse_command); vfs_path_free (p_vpath); }
/* *INDENT-OFF* */ START_PARAMETRIZED_TEST (test_relative_cd, test_relative_cd_ds) /* *INDENT-ON* */ { /* given */ vfs_path_t *vpath; int actual_result; test_chdir__return_value = 0; vpath = vfs_path_from_str_flags (data->input_string, data->input_flags); /* when */ actual_result = mc_chdir (vpath); /* then */ { const vfs_path_element_t *element; mctest_assert_int_eq (actual_result, 0); element = vfs_path_get_by_index (vpath, -1); mctest_assert_str_eq (element->path, data->expected_element_path); vfs_path_free (vpath); } }
END_TEST /* --------------------------------------------------------------------------------------------- */ START_TEST (test_vfs_path_from_to_partial_string_by_class) { vfs_path_t *vpath; char *result; vpath = vfs_path_from_str_flags (ETALON_PATH_STR, VPF_USE_DEPRECATED_PARSER); result = vfs_path_to_str_elements_count(vpath, -1); fail_unless( strcmp("/test1://bla-bla/some/path/test2://bla-bla/some/path", result) == 0, "expected(%s) doesn't equal to actual(%s)", "/test1://bla-bla/some/path/test2://bla-bla/some/path", result); g_free(result); result = vfs_path_to_str_elements_count(vpath, -2); fail_unless( strcmp("/test1://bla-bla/some/path/", result) == 0, "expected(%s) doesn't equal to actual(%s)", "/test1://bla-bla/some/path/", result); g_free(result); result = vfs_path_to_str_elements_count(vpath, -3); fail_unless( strcmp("/", result) == 0, "expected(%s) doesn't equal to actual(%s)", "/", result); g_free(result); /* index out of bound*/ result = vfs_path_to_str_elements_count(vpath, -4); fail_unless( strcmp("", result) == 0, "expected(%s) doesn't equal to actual(%s)", "", result); g_free(result); result = vfs_path_to_str_elements_count(vpath, 1); fail_unless( strcmp("/", result) == 0, "expected(%s) doesn't equal to actual(%s)", "/", result); g_free(result); result = vfs_path_to_str_elements_count(vpath, 2); fail_unless( strcmp("/test1://bla-bla/some/path/", result) == 0, "expected(%s) doesn't equal to actual(%s)", "/test1://bla-bla/some/path/", result); g_free(result); result = vfs_path_to_str_elements_count(vpath, 3); fail_unless( strcmp("/test1://bla-bla/some/path/test2://bla-bla/some/path", result) == 0, "expected(%s) doesn't equal to actual(%s)", "/test1://bla-bla/some/path/test2://bla-bla/some/path", result); g_free(result); result = vfs_path_to_str_elements_count(vpath, 4); fail_unless( strcmp(ETALON_PATH_URL_STR, result) == 0, "expected(%s) doesn't equal to actual(%s)", ETALON_PATH_URL_STR, result); g_free(result); /* index out of bound*/ result = vfs_path_to_str_elements_count(vpath, 5); fail_unless( strcmp(ETALON_PATH_URL_STR, result) == 0, "expected(%s) doesn't equal to actual(%s)", ETALON_PATH_URL_STR, result); g_free(result); vfs_path_free(vpath); }
char * file_mask_dialog (FileOpContext * ctx, FileOperation operation, gboolean only_one, const char *format, const void *text, const char *def_text, gboolean * do_bg) { const size_t FMDY = 13; const size_t FMDX = 68; size_t fmd_xlen; /* buttons */ const size_t gap = 1; size_t b0_len, b2_len; size_t b1_len = 0; int source_easy_patterns = easy_patterns; size_t i, len; char fmd_buf[BUF_MEDIUM]; char *source_mask, *orig_mask, *dest_dir, *tmp; char *def_text_secure; int val; QuickWidget fmd_widgets[] = { /* 0 */ QUICK_BUTTON (42, 64, 10, FMDY, N_("&Cancel"), B_CANCEL, NULL), #ifdef ENABLE_BACKGROUND /* 1 */ QUICK_BUTTON (25, 64, 10, FMDY, N_("&Background"), B_USER, NULL), #define OFFSET 0 #else #define OFFSET 1 #endif /* ENABLE_BACKGROUND */ /* 2 - OFFSET */ QUICK_BUTTON (14, FMDX, 10, FMDY, N_("&OK"), B_ENTER, NULL), /* 3 - OFFSET */ QUICK_CHECKBOX (42, FMDX, 8, FMDY, N_("&Stable Symlinks"), &ctx->stable_symlinks), /* 4 - OFFSET */ QUICK_CHECKBOX (31, FMDX, 7, FMDY, N_("Di&ve into subdir if exists"), &ctx->dive_into_subdirs), /* 5 - OFFSET */ QUICK_CHECKBOX (3, FMDX, 8, FMDY, N_("Preserve &attributes"), &ctx->op_preserve), /* 6 - OFFSET */ QUICK_CHECKBOX (3, FMDX, 7, FMDY, N_("Follow &links"), &ctx->follow_links), /* 7 - OFFSET */ QUICK_INPUT (3, FMDX, 6, FMDY, "", 58, 0, "input2", &dest_dir), /* 8 - OFFSET */ QUICK_LABEL (3, FMDX, 5, FMDY, N_("to:")), /* 9 - OFFSET */ QUICK_CHECKBOX (37, FMDX, 4, FMDY, N_("&Using shell patterns"), &source_easy_patterns), /* 10 - OFFSET */ QUICK_INPUT (3, FMDX, 3, FMDY, easy_patterns ? "*" : "^(.*)$", 58, 0, "input-def", &source_mask), /* 11 - OFFSET */ QUICK_LABEL (3, FMDX, 2, FMDY, fmd_buf), QUICK_END }; g_return_val_if_fail (ctx != NULL, NULL); #ifdef ENABLE_NLS /* buttons */ for (i = 0; i <= 2 - OFFSET; i++) fmd_widgets[i].u.button.text = _(fmd_widgets[i].u.button.text); /* checkboxes */ for (i = 3 - OFFSET; i <= 9 - OFFSET; i++) if (i != 7 - OFFSET) fmd_widgets[i].u.checkbox.text = _(fmd_widgets[i].u.checkbox.text); #endif /* !ENABLE_NLS */ fmd_xlen = max (FMDX, (size_t) COLS * 2 / 3); len = str_term_width1 (fmd_widgets[6 - OFFSET].u.checkbox.text) + str_term_width1 (fmd_widgets[4 - OFFSET].u.checkbox.text) + 15; fmd_xlen = max (fmd_xlen, len); len = str_term_width1 (fmd_widgets[5 - OFFSET].u.checkbox.text) + str_term_width1 (fmd_widgets[3 - OFFSET].u.checkbox.text) + 15; fmd_xlen = max (fmd_xlen, len); /* buttons */ b2_len = str_term_width1 (fmd_widgets[2 - OFFSET].u.button.text) + 6 + gap; /* OK */ #ifdef ENABLE_BACKGROUND b1_len = str_term_width1 (fmd_widgets[1].u.button.text) + 4 + gap; /* Background */ #endif b0_len = str_term_width1 (fmd_widgets[0].u.button.text) + 4; /* Cancel */ len = b0_len + b1_len + b2_len; fmd_xlen = min (max (fmd_xlen, len + 6), (size_t) COLS); if (only_one) { int flen; flen = str_term_width1 (format); i = fmd_xlen - flen - 4; /* FIXME */ g_snprintf (fmd_buf, sizeof (fmd_buf), format, str_trunc ((const char *) text, i)); } else { g_snprintf (fmd_buf, sizeof (fmd_buf), format, *(const int *) text); fmd_xlen = max (fmd_xlen, (size_t) str_term_width1 (fmd_buf) + 6); } for (i = sizeof (fmd_widgets) / sizeof (fmd_widgets[0]); i > 0;) fmd_widgets[--i].x_divisions = fmd_xlen; i = (fmd_xlen - len) / 2; /* OK button */ fmd_widgets[2 - OFFSET].relative_x = i; i += b2_len; #ifdef ENABLE_BACKGROUND /* Background button */ fmd_widgets[1].relative_x = i; i += b1_len; #endif /* Cancel button */ fmd_widgets[0].relative_x = i; #define chkbox_xpos(i) \ fmd_widgets [i].relative_x = fmd_xlen - str_term_width1 (fmd_widgets [i].u.checkbox.text) - 6 chkbox_xpos (3 - OFFSET); chkbox_xpos (4 - OFFSET); chkbox_xpos (9 - OFFSET); #undef chkbox_xpos /* inputs */ fmd_widgets[7 - OFFSET].u.input.len = fmd_widgets[10 - OFFSET].u.input.len = fmd_xlen - 6; /* unselect checkbox if target filesystem don't support attributes */ ctx->op_preserve = filegui__check_attrs_on_fs (def_text); /* filter out a possible password from def_text */ { vfs_path_t *vpath; vpath = vfs_path_from_str_flags (def_text, (only_one) ? VPF_NO_CANON : VPF_NONE); tmp = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD); vfs_path_free (vpath); } if (source_easy_patterns) def_text_secure = strutils_glob_escape (tmp); else def_text_secure = strutils_regex_escape (tmp); g_free (tmp); /* destination */ fmd_widgets[7 - OFFSET].u.input.text = def_text_secure; ctx->stable_symlinks = FALSE; *do_bg = FALSE; { struct stat buf; vfs_path_t *vpath; QuickDialog Quick_input = { fmd_xlen, FMDY, -1, -1, op_names[operation], "[Mask Copy/Rename]", fmd_widgets, NULL, NULL, TRUE }; ask_file_mask: val = quick_dialog_skip (&Quick_input, 4); if (val == B_CANCEL) { g_free (def_text_secure); return NULL; } if (ctx->follow_links) ctx->stat_func = mc_stat; else ctx->stat_func = mc_lstat; if (ctx->op_preserve) { ctx->preserve = TRUE; ctx->umask_kill = 0777777; ctx->preserve_uidgid = (geteuid () == 0); } else { int i2; ctx->preserve = ctx->preserve_uidgid = FALSE; i2 = umask (0); umask (i2); ctx->umask_kill = i2 ^ 0777777; } if ((dest_dir == NULL) || (*dest_dir == '\0')) { g_free (def_text_secure); g_free (source_mask); return dest_dir; } ctx->search_handle = mc_search_new (source_mask, -1); if (ctx->search_handle == NULL) { message (D_ERROR, MSG_ERROR, _("Invalid source pattern `%s'"), source_mask); g_free (dest_dir); g_free (source_mask); goto ask_file_mask; } g_free (def_text_secure); g_free (source_mask); ctx->search_handle->is_case_sensitive = TRUE; if (source_easy_patterns) ctx->search_handle->search_type = MC_SEARCH_T_GLOB; else ctx->search_handle->search_type = MC_SEARCH_T_REGEX; tmp = dest_dir; dest_dir = tilde_expand (tmp); g_free (tmp); vpath = vfs_path_from_str (dest_dir); ctx->dest_mask = strrchr (dest_dir, PATH_SEP); if (ctx->dest_mask == NULL) ctx->dest_mask = dest_dir; else ctx->dest_mask++; orig_mask = ctx->dest_mask; if (*ctx->dest_mask == '\0' || (!ctx->dive_into_subdirs && !is_wildcarded (ctx->dest_mask) && (!only_one || (mc_stat (vpath, &buf) == 0 && S_ISDIR (buf.st_mode)))) || (ctx->dive_into_subdirs && ((!only_one && !is_wildcarded (ctx->dest_mask)) || (only_one && mc_stat (vpath, &buf) == 0 && S_ISDIR (buf.st_mode))))) ctx->dest_mask = g_strdup ("\\0"); else { ctx->dest_mask = g_strdup (ctx->dest_mask); *orig_mask = '\0'; } if (!*dest_dir) { g_free (dest_dir); dest_dir = g_strdup ("./"); } vfs_path_free (vpath); if (val == B_USER) *do_bg = TRUE; } return dest_dir; }
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); }
void do_cd_command (char *orig_cmd) { int len; int operand_pos = CD_OPERAND_OFFSET; const char *cmd; /* Any final whitespace should be removed here (to see why, try "cd fred "). */ /* NOTE: I think we should not remove the extra space, that way, we can cd into hidden directories */ /* FIXME: what about interpreting quoted strings like the shell. so one could type "cd <tab> M-a <enter>" and it would work. */ len = strlen (orig_cmd) - 1; while (len >= 0 && (orig_cmd[len] == ' ' || orig_cmd[len] == '\t' || orig_cmd[len] == '\n')) { orig_cmd[len] = 0; len--; } cmd = orig_cmd; if (cmd[CD_OPERAND_OFFSET - 1] == 0) cmd = "cd "; /* 0..2 => given text, 3 => \0 */ /* allow any amount of white space in front of the path operand */ while (cmd[operand_pos] == ' ' || cmd[operand_pos] == '\t') operand_pos++; if (get_current_type () == view_tree) { if (cmd[0] == 0) { sync_tree (mc_config_get_home_dir ()); } else if (DIR_IS_DOTDOT (cmd + operand_pos)) { if (vfs_path_elements_count (current_panel->cwd_vpath) != 1 || strlen (vfs_path_get_by_index (current_panel->cwd_vpath, 0)->path) > 1) { vfs_path_t *tmp_vpath = current_panel->cwd_vpath; current_panel->cwd_vpath = vfs_path_vtokens_get (tmp_vpath, 0, vfs_path_tokens_count (tmp_vpath) - 1); vfs_path_free (tmp_vpath); } sync_tree (vfs_path_as_str (current_panel->cwd_vpath)); } else if (cmd[operand_pos] == PATH_SEP) { sync_tree (cmd + operand_pos); } else { vfs_path_t *new_vpath; new_vpath = vfs_path_append_new (current_panel->cwd_vpath, cmd + operand_pos, NULL); sync_tree (vfs_path_as_str (new_vpath)); vfs_path_free (new_vpath); } } else { char *path; vfs_path_t *q_vpath; gboolean ok; path = examine_cd (&cmd[operand_pos]); if (*path == '\0') q_vpath = vfs_path_from_str (mc_config_get_home_dir ()); else q_vpath = vfs_path_from_str_flags (path, VPF_NO_CANON); ok = do_cd (q_vpath, cd_parse_command); if (!ok) ok = handle_cdpath (path); if (!ok) { char *d; d = vfs_path_to_str_flags (q_vpath, 0, VPF_STRIP_PASSWORD); message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), d, unix_error_string (errno)); g_free (d); } vfs_path_free (q_vpath); g_free (path); } }
char * file_mask_dialog (file_op_context_t * ctx, FileOperation operation, gboolean only_one, const char *format, const void *text, const char *def_text, gboolean * do_bg) { size_t fmd_xlen; vfs_path_t *vpath; int source_easy_patterns = easy_patterns; char fmd_buf[BUF_MEDIUM]; char *dest_dir, *tmp; char *def_text_secure; if (ctx == NULL) return NULL; /* unselect checkbox if target filesystem don't support attributes */ ctx->op_preserve = filegui__check_attrs_on_fs (def_text); ctx->stable_symlinks = FALSE; *do_bg = FALSE; /* filter out a possible password from def_text */ vpath = vfs_path_from_str_flags (def_text, only_one ? VPF_NO_CANON : VPF_NONE); tmp = vfs_path_to_str_flags (vpath, 0, VPF_STRIP_PASSWORD); vfs_path_free (vpath); if (source_easy_patterns) def_text_secure = strutils_glob_escape (tmp); else def_text_secure = strutils_regex_escape (tmp); g_free (tmp); if (only_one) { int format_len, text_len; int max_len; format_len = str_term_width1 (format); text_len = str_term_width1 (text); max_len = COLS - 2 - 6; if (format_len + text_len <= max_len) { fmd_xlen = format_len + text_len + 6; fmd_xlen = max (fmd_xlen, 68); } else { text = str_trunc ((const char *) text, max_len - format_len); fmd_xlen = max_len + 6; } g_snprintf (fmd_buf, sizeof (fmd_buf), format, (const char *) text); } else { fmd_xlen = COLS * 2 / 3; fmd_xlen = max (fmd_xlen, 68); g_snprintf (fmd_buf, sizeof (fmd_buf), format, *(const int *) text); } { char *source_mask, *orig_mask; int val; struct stat buf; quick_widget_t quick_widgets[] = { /* *INDENT-OFF* */ QUICK_LABELED_INPUT (fmd_buf, input_label_above, easy_patterns ? "*" : "^(.*)$", "input-def", &source_mask, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES), QUICK_START_COLUMNS, QUICK_SEPARATOR (FALSE), QUICK_NEXT_COLUMN, QUICK_CHECKBOX (N_("&Using shell patterns"), &source_easy_patterns, NULL), QUICK_STOP_COLUMNS, QUICK_LABELED_INPUT (N_("to:"), input_label_above, def_text_secure, "input2", &dest_dir, NULL, FALSE, FALSE, INPUT_COMPLETE_FILENAMES), QUICK_SEPARATOR (TRUE), QUICK_START_COLUMNS, QUICK_CHECKBOX (N_("Follow &links"), &ctx->follow_links, NULL), QUICK_CHECKBOX (N_("Preserve &attributes"), &ctx->op_preserve, NULL), QUICK_NEXT_COLUMN, QUICK_CHECKBOX (N_("Di&ve into subdir if exists"), &ctx->dive_into_subdirs, NULL), QUICK_CHECKBOX (N_("&Stable symlinks"), &ctx->stable_symlinks, NULL), QUICK_STOP_COLUMNS, QUICK_START_BUTTONS (TRUE, TRUE), QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL), #ifdef ENABLE_BACKGROUND QUICK_BUTTON (N_("&Background"), B_USER, NULL, NULL), #endif /* ENABLE_BACKGROUND */ QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL), QUICK_END /* *INDENT-ON* */ }; quick_dialog_t qdlg = { -1, -1, fmd_xlen, op_names[operation], "[Mask Copy/Rename]", quick_widgets, NULL, NULL }; ask_file_mask: val = quick_dialog_skip (&qdlg, 4); if (val == B_CANCEL) { g_free (def_text_secure); return NULL; } if (ctx->follow_links) ctx->stat_func = mc_stat; else ctx->stat_func = mc_lstat; if (ctx->op_preserve) { ctx->preserve = TRUE; ctx->umask_kill = 0777777; ctx->preserve_uidgid = (geteuid () == 0); } else { int i2; ctx->preserve = ctx->preserve_uidgid = FALSE; i2 = umask (0); umask (i2); ctx->umask_kill = i2 ^ 0777777; } if ((dest_dir == NULL) || (*dest_dir == '\0')) { g_free (def_text_secure); g_free (source_mask); return dest_dir; } ctx->search_handle = mc_search_new (source_mask, -1, NULL); if (ctx->search_handle == NULL) { message (D_ERROR, MSG_ERROR, _("Invalid source pattern '%s'"), source_mask); g_free (dest_dir); g_free (source_mask); goto ask_file_mask; } g_free (def_text_secure); g_free (source_mask); ctx->search_handle->is_case_sensitive = TRUE; if (source_easy_patterns) ctx->search_handle->search_type = MC_SEARCH_T_GLOB; else ctx->search_handle->search_type = MC_SEARCH_T_REGEX; vpath = vfs_path_from_str (dest_dir); ctx->dest_mask = strrchr (dest_dir, PATH_SEP); if (ctx->dest_mask == NULL) ctx->dest_mask = dest_dir; else ctx->dest_mask++; orig_mask = ctx->dest_mask; if (*ctx->dest_mask == '\0' || (!ctx->dive_into_subdirs && !is_wildcarded (ctx->dest_mask) && (!only_one || (mc_stat (vpath, &buf) == 0 && S_ISDIR (buf.st_mode)))) || (ctx->dive_into_subdirs && ((!only_one && !is_wildcarded (ctx->dest_mask)) || (only_one && mc_stat (vpath, &buf) == 0 && S_ISDIR (buf.st_mode))))) ctx->dest_mask = g_strdup ("\\0"); else { ctx->dest_mask = g_strdup (ctx->dest_mask); *orig_mask = '\0'; } if (*dest_dir == '\0') { g_free (dest_dir); dest_dir = g_strdup ("./"); } vfs_path_free (vpath); if (val == B_USER) *do_bg = TRUE; } return dest_dir; }