mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 10:04:32 +03:00
Refactor preparation of file/dir operation.
(transform_source): rename to build_dest and really build destination file name here. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
1337ed1c55
commit
1071c232c7
@ -183,8 +183,6 @@ static GSList *erase_list = NULL;
|
|||||||
*/
|
*/
|
||||||
static GSList *dest_dirs = NULL;
|
static GSList *dest_dirs = NULL;
|
||||||
|
|
||||||
static FileProgressStatus transform_error = FILE_CONT;
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*** file scope functions ************************************************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -223,12 +221,14 @@ dirsize_status_locate_buttons (dirsize_status_msg_t * dsm)
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
transform_source (file_op_context_t * ctx, const vfs_path_t * source_vpath)
|
build_dest (file_op_context_t * ctx, const char *src, const char *dest, FileProgressStatus * status)
|
||||||
{
|
{
|
||||||
char *s, *q;
|
char *s, *q;
|
||||||
const char *fnsource;
|
const char *fnsource;
|
||||||
|
|
||||||
s = g_strdup (vfs_path_as_str (source_vpath));
|
*status = FILE_CONT;
|
||||||
|
|
||||||
|
s = g_strdup (src);
|
||||||
|
|
||||||
/* We remove \n from the filename since regex routines would use \n as an anchor */
|
/* We remove \n from the filename since regex routines would use \n as an anchor */
|
||||||
/* this is just to be allowed to maniupulate file names with \n on it */
|
/* this is just to be allowed to maniupulate file names with \n on it */
|
||||||
@ -238,7 +238,12 @@ transform_source (file_op_context_t * ctx, const vfs_path_t * source_vpath)
|
|||||||
|
|
||||||
fnsource = x_basename (s);
|
fnsource = x_basename (s);
|
||||||
|
|
||||||
if (mc_search_run (ctx->search_handle, fnsource, 0, strlen (fnsource), NULL))
|
if (!mc_search_run (ctx->search_handle, fnsource, 0, strlen (fnsource), NULL))
|
||||||
|
{
|
||||||
|
q = NULL;
|
||||||
|
*status = FILE_SKIP;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
q = mc_search_prepare_replace_str2 (ctx->search_handle, ctx->dest_mask);
|
q = mc_search_prepare_replace_str2 (ctx->search_handle, ctx->dest_mask);
|
||||||
if (ctx->search_handle->error != MC_SEARCH_E_OK)
|
if (ctx->search_handle->error != MC_SEARCH_E_OK)
|
||||||
@ -246,19 +251,33 @@ transform_source (file_op_context_t * ctx, const vfs_path_t * source_vpath)
|
|||||||
if (ctx->search_handle->error_str != NULL)
|
if (ctx->search_handle->error_str != NULL)
|
||||||
message (D_ERROR, MSG_ERROR, "%s", ctx->search_handle->error_str);
|
message (D_ERROR, MSG_ERROR, "%s", ctx->search_handle->error_str);
|
||||||
|
|
||||||
g_free (q);
|
*status = FILE_ABORT;
|
||||||
q = NULL;
|
|
||||||
transform_error = FILE_ABORT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
MC_PTR_FREE (s);
|
||||||
|
|
||||||
|
if (*status == FILE_CONT)
|
||||||
{
|
{
|
||||||
q = NULL;
|
char *repl_dest;
|
||||||
transform_error = FILE_SKIP;
|
|
||||||
|
repl_dest = mc_search_prepare_replace_str2 (ctx->search_handle, dest);
|
||||||
|
if (ctx->search_handle->error == MC_SEARCH_E_OK)
|
||||||
|
s = mc_build_filename (repl_dest, q, (char *) NULL);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ctx->search_handle->error_str != NULL)
|
||||||
|
message (D_ERROR, MSG_ERROR, "%s", ctx->search_handle->error_str);
|
||||||
|
|
||||||
|
*status = FILE_ABORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (repl_dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (s);
|
g_free (q);
|
||||||
return q;
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -1690,30 +1709,12 @@ operate_single_file (const WPanel * panel, FileOperation operation, file_op_tota
|
|||||||
{
|
{
|
||||||
char *temp;
|
char *temp;
|
||||||
|
|
||||||
temp = transform_source (ctx, src_vpath);
|
src = vfs_path_as_str (src_vpath);
|
||||||
if (temp == NULL)
|
|
||||||
value = transform_error;
|
temp = build_dest (ctx, src, dest, &value);
|
||||||
else
|
if (temp != NULL)
|
||||||
{
|
{
|
||||||
char *repl_dest, *temp2;
|
dest = temp;
|
||||||
|
|
||||||
repl_dest = mc_search_prepare_replace_str2 (ctx->search_handle, dest);
|
|
||||||
if (ctx->search_handle->error != MC_SEARCH_E_OK)
|
|
||||||
{
|
|
||||||
if (ctx->search_handle->error_str != NULL)
|
|
||||||
message (D_ERROR, MSG_ERROR, "%s", ctx->search_handle->error_str);
|
|
||||||
|
|
||||||
g_free (repl_dest);
|
|
||||||
value = FILE_ABORT;
|
|
||||||
goto ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp2 = mc_build_filename (repl_dest, temp, (char *) NULL);
|
|
||||||
g_free (temp);
|
|
||||||
g_free (repl_dest);
|
|
||||||
|
|
||||||
src = vfs_path_as_str (src_vpath);
|
|
||||||
dest = temp2;
|
|
||||||
|
|
||||||
switch (operation)
|
switch (operation)
|
||||||
{
|
{
|
||||||
@ -1740,7 +1741,7 @@ operate_single_file (const WPanel * panel, FileOperation operation, file_op_tota
|
|||||||
abort ();
|
abort ();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (temp2);
|
g_free (temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1778,34 +1779,19 @@ operate_one_file (const WPanel * panel, FileOperation operation, file_op_total_c
|
|||||||
{
|
{
|
||||||
char *temp;
|
char *temp;
|
||||||
|
|
||||||
temp = transform_source (ctx, src_vpath);
|
src = vfs_path_as_str (src_vpath);
|
||||||
if (temp == NULL)
|
|
||||||
value = transform_error;
|
temp = build_dest (ctx, src, dest, &value);
|
||||||
else
|
if (temp != NULL)
|
||||||
{
|
{
|
||||||
char *repl_dest, *temp2, *src2;
|
char *src2, *temp2;
|
||||||
|
|
||||||
repl_dest = mc_search_prepare_replace_str2 (ctx->search_handle, dest);
|
src2 = strutils_shell_unescape (src);
|
||||||
if (ctx->search_handle->error != MC_SEARCH_E_OK)
|
temp2 = strutils_shell_unescape (temp);
|
||||||
{
|
|
||||||
if (ctx->search_handle->error_str != NULL)
|
|
||||||
message (D_ERROR, MSG_ERROR, "%s", ctx->search_handle->error_str);
|
|
||||||
|
|
||||||
g_free (repl_dest);
|
|
||||||
value = FILE_ABORT;
|
|
||||||
goto ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp2 = mc_build_filename (repl_dest, temp, (char *) NULL);
|
|
||||||
g_free (temp);
|
g_free (temp);
|
||||||
g_free (repl_dest);
|
|
||||||
|
|
||||||
src2 = strutils_shell_unescape (vfs_path_as_str (src_vpath));
|
|
||||||
temp = strutils_shell_unescape (temp2);
|
|
||||||
g_free (temp2);
|
|
||||||
|
|
||||||
src = src2;
|
src = src2;
|
||||||
dest = temp;
|
dest = temp2;
|
||||||
|
|
||||||
switch (operation)
|
switch (operation)
|
||||||
{
|
{
|
||||||
@ -1836,11 +1822,10 @@ operate_one_file (const WPanel * panel, FileOperation operation, file_op_total_c
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_free (src2);
|
g_free (src2);
|
||||||
g_free (temp);
|
g_free (temp2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret:
|
|
||||||
vfs_path_free (src_vpath);
|
vfs_path_free (src_vpath);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
Loading…
Reference in New Issue
Block a user