fix: check if path is a dir

This commit is contained in:
Quinten Mennen 2025-02-27 15:58:18 +01:00
parent 90678d8f0f
commit 13adfc5a07

View File

@ -6,11 +6,24 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <sys/stat.h>
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);