mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 04:22:34 +03:00
Ticket #4377: file type check does not work with special character in filename.
Initial commit: clarify usage of "file" utility. * (get_popen_information): compile conditionally depending on USE_FILE_CMD macro. * (get_file_type_local): likewise. * (get_file_encoding_local): likewise. * (regex_check_type): likewise. * (regex_command_for): ignore type method if file utiliti isn't used. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
6c45208744
commit
0bb9c04720
@ -25,6 +25,8 @@
|
||||
#
|
||||
# type (file matches this if `file %f` matches regular expression desc
|
||||
# (the filename: part from `file %f` is removed))
|
||||
# Ignored if the "file" utility isn't used (not found in configure
|
||||
step or disabled in ini file).
|
||||
#
|
||||
# type/i (file matches this if `file %f` matches regular expression desc)
|
||||
# The same as type but with case insensitive.
|
||||
|
@ -50,7 +50,9 @@
|
||||
#include "lib/charsets.h" /* get_codepage_index */
|
||||
#endif
|
||||
|
||||
#ifdef USE_FILE_CMD
|
||||
#include "src/setup.h" /* use_file_to_check_type */
|
||||
#endif
|
||||
#include "src/execute.h"
|
||||
#include "src/history.h"
|
||||
#include "src/usermenu.h"
|
||||
@ -73,9 +75,6 @@
|
||||
|
||||
#ifdef USE_FILE_CMD
|
||||
#define FILE_CMD "file -z " FILE_S FILE_L
|
||||
#else
|
||||
/* actually file is unused, but define some reasonable command */
|
||||
#define FILE_CMD "file "
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
@ -540,6 +539,7 @@ exec_extension (WPanel * panel, void *target, const vfs_path_t * filename_vpath,
|
||||
* NOTES: buf is null-terminated string.
|
||||
*/
|
||||
|
||||
#ifdef USE_FILE_CMD
|
||||
static int
|
||||
get_popen_information (const char *cmd_file, const char *args, char *buf, int buflen)
|
||||
{
|
||||
@ -643,9 +643,6 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
|
||||
|
||||
mc_return_val_if_error (mcerror, FALSE);
|
||||
|
||||
if (!use_file_to_check_type)
|
||||
return FALSE;
|
||||
|
||||
if (!*have_type)
|
||||
{
|
||||
vfs_path_t *localfile_vpath;
|
||||
@ -752,6 +749,7 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c
|
||||
|
||||
return found;
|
||||
}
|
||||
#endif /* USE_FILE_CMD */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
@ -792,7 +790,9 @@ regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *
|
||||
int view_at_line_number = 0;
|
||||
char *include_target = NULL;
|
||||
size_t include_target_len = 0;
|
||||
#ifdef USE_FILE_CMD
|
||||
gboolean have_type = FALSE; /* Flag used by regex_check_type() */
|
||||
#endif
|
||||
|
||||
if (filename_vpath == NULL)
|
||||
return 0;
|
||||
@ -961,7 +961,8 @@ regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *
|
||||
found = TRUE;
|
||||
}
|
||||
}
|
||||
else if (strncmp (p, "type/", 5) == 0)
|
||||
#ifdef USE_FILE_CMD
|
||||
else if (use_file_to_check_type && strncmp (p, "type/", 5) == 0)
|
||||
{
|
||||
GError *mcerror = NULL;
|
||||
|
||||
@ -975,6 +976,7 @@ regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *
|
||||
if (mc_error_message (&mcerror, NULL))
|
||||
error_flag = TRUE; /* leave it if file cannot be opened */
|
||||
}
|
||||
#endif /* USE_FILE_CMD */
|
||||
else if (strncmp (p, "default/", 8) == 0)
|
||||
found = TRUE;
|
||||
|
||||
|
@ -164,8 +164,10 @@ gboolean auto_fill_mkdir_name = TRUE;
|
||||
/* If set and you don't have subshell support, then C-o will give you a shell */
|
||||
gboolean output_starts_shell = FALSE;
|
||||
|
||||
#ifdef USE_FILE_CMD
|
||||
/* If set, we execute the file command to check the file type */
|
||||
gboolean use_file_to_check_type = TRUE;
|
||||
#endif
|
||||
|
||||
gboolean verbose = TRUE;
|
||||
|
||||
|
@ -96,7 +96,9 @@ extern gboolean only_leading_plus_minus;
|
||||
extern int cd_symlinks;
|
||||
extern gboolean auto_fill_mkdir_name;
|
||||
extern gboolean output_starts_shell;
|
||||
#ifdef USE_FILE_CMD
|
||||
extern gboolean use_file_to_check_type;
|
||||
#endif
|
||||
extern gboolean file_op_compute_totals;
|
||||
extern gboolean editor_ask_filename_before_edit;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user