mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「🔨」 fix(exec/check_file): check if path is a directory
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/07/13 14:03:47 by adjoly ### ########.fr */
|
/* Updated: 2024/07/14 15:49:21 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -36,6 +36,7 @@ char *get_cmd_local_path(char *cmd, t_env *env);
|
|||||||
void print_return_value(int return_code);
|
void print_return_value(int return_code);
|
||||||
void __wait(int i);
|
void __wait(int i);
|
||||||
void __close(void *content);
|
void __close(void *content);
|
||||||
|
int check_file(char *cmd, char *input);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief spawn a heredoc
|
* @brief spawn a heredoc
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/07/14 14:44:18 by adjoly ### ########.fr */
|
/* Updated: 2024/07/14 15:48:41 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -70,10 +70,10 @@ int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
|
|||||||
exec.pipe_fd[0] = pipe_fd[0];
|
exec.pipe_fd[0] = pipe_fd[0];
|
||||||
exec.pipe_fd[1] = pipe_fd[1];
|
exec.pipe_fd[1] = pipe_fd[1];
|
||||||
exec.status = switch_cmd_path(cmd, env_t);
|
exec.status = switch_cmd_path(cmd, env_t);
|
||||||
if (exec.status == -1 || !input || (access(cmd->cmd, X_OK) \
|
if (exec.status == -1 || !input || check_file(cmd->cmd, input))
|
||||||
&& !is_in_builtins(cmd->cmd)))
|
|
||||||
{
|
{
|
||||||
printf("minishell : command not found: %s$\n", input);
|
if (exec.status == -1)
|
||||||
|
printf("minishell : command not found: %s\n", input);
|
||||||
free(input);
|
free(input);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/09 19:25:18 by adjoly #+# #+# */
|
/* Created: 2024/07/09 19:25:18 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/07/10 01:17:11 by adjoly ### ########.fr */
|
/* Updated: 2024/07/14 15:49:04 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -89,3 +89,25 @@ int switch_cmd_path(t_cmd *cmd, t_env *env)
|
|||||||
return (-1);
|
return (-1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int check_file(char *cmd, char *input)
|
||||||
|
{
|
||||||
|
struct stat entry;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
if (is_in_builtins(cmd))
|
||||||
|
return (0);
|
||||||
|
status = stat(cmd, &entry);
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
printf("minishell : command not found: %s\n", input);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (!S_ISDIR(entry.st_mode) && !access(cmd, X_OK))
|
||||||
|
return (0);
|
||||||
|
if (S_ISDIR(entry.st_mode))
|
||||||
|
printf("minishell : %s is a directory.\n", input);
|
||||||
|
else
|
||||||
|
printf("minishell : command not found: %s\n", input);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user