fix(wildcard): error handling for wildcard expansion in redirections

This commit is contained in:
Khaïs COLIN 2025-04-30 15:03:30 +02:00
parent 04eabf096d
commit 826abdf623
3 changed files with 17 additions and 4 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/27 16:21:56 by kcolin #+# #+# */
/* Updated: 2025/04/30 14:05:26 by kcolin ### ########.fr */
/* Updated: 2025/04/30 15:08:01 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -114,7 +114,7 @@ t_subprocess simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
ft_errno(FT_ESUCCESS);
if (post_process_command(cmd, app) == NULL)
{
if (ft_errno_get() != FT_ESUCCESS)
if (ft_errno_get() != FT_ESUCCESS && errno != 0)
ft_dprintf(STDERR_FILENO, "minishell: post-processing error\n");
return (PARENTPROCESS);
}

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/03 19:28:28 by kcolin #+# #+# */
/* Updated: 2025/04/30 14:51:12 by kcolin ### ########.fr */
/* Updated: 2025/04/30 15:09:59 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,7 @@ static t_redirect *redirect_expand_wildcard_one(t_redirect *current)
{
t_wordlist *expansion_result;
ft_errno(FT_ESUCCESS);
expansion_result = expand_star(current->redirectee.filename);
if (expansion_result != NULL)
{
@ -34,6 +35,8 @@ static t_redirect *redirect_expand_wildcard_one(t_redirect *current)
return (ft_errno(FT_EERRNO), NULL);
}
}
else if (expansion_result == NULL && ft_errno_get() != FT_ESUCCESS)
return (redirect_destroy(current), NULL);
return (current);
}
@ -48,7 +51,9 @@ static t_redirect *redirect_expand_wildcards(t_redirect *in_list)
current = redirect_pop(&in_list);
if (current->type != FT_HEREDOC)
{
if (redirect_expand_wildcard_one(current) == NULL)
ft_errno(FT_ESUCCESS);
if (redirect_expand_wildcard_one(current) == NULL
&& ft_errno_get() != FT_ESUCCESS)
{
redirect_destroy(in_list);
redirect_destroy(out_list);

View file

@ -1602,4 +1602,12 @@ expecting <<EOF
hi
EOF
when_run <<EOF "wildcard redirect ambiguous"
touch a.txt b.txt
echo hello > *.txt
EOF
expecting <<EOF
minishell: *.txt: ambiguous redirect
EOF
finalize