From 13adfc5a0740f244aff4cb278f168c96f9b740a0 Mon Sep 17 00:00:00 2001 From: Quinten Mennen Date: Thu, 27 Feb 2025 15:58:18 +0100 Subject: [PATCH] fix: check if path is a dir --- src/executor/executor_child.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/executor/executor_child.c b/src/executor/executor_child.c index 299b77c..cebe4c9 100644 --- a/src/executor/executor_child.c +++ b/src/executor/executor_child.c @@ -6,11 +6,24 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/12 21:25:10 by willem #+# #+# */ -/* Updated: 2025/02/26 18:20:34 by qmennen ### ########.fr */ +/* Updated: 2025/02/27 13:50:26 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +#include + +static int is_dir(char *path) +{ + struct stat path_stats; + + if (stat(path, &path_stats) < 0) + { + error_msg("is_dir", "path could not be read"); + return (0); + } + return S_ISDIR(path_stats.st_mode); +} void executor_child(t_minishell *msh, t_command *command) { @@ -22,7 +35,14 @@ void executor_child(t_minishell *msh, t_command *command) dup2(command->fd_out, 1); executor_close_fds(command->n_fds); path = executor_absolute_path(msh, command->args[0]); - if (path == NULL || !access(path, F_OK | X_OK)) + // TODO: If the path variable points to a dir, it exists so the command won't fail (while ofc it should?) + if (is_dir(path)) + { + ft_putstr_fd(RED BOLD, 2); + ft_putstr_fd(command->args[0], 2); + ft_putstr_fd(": " RESET "is a directory\n", 2); + } + if (path == NULL || access(path, F_OK | X_OK) != 0) { ft_putstr_fd(RED BOLD, 2); ft_putstr_fd(command->args[0], 2);