fix: permission on redirection fiel

This commit is contained in:
starnakin 2023-07-05 00:45:35 +02:00
parent e9e80c192e
commit 96f7108555

View File

@ -42,26 +42,25 @@ void redirection_fill(const char* str, size_t nb_symbols, cmd_t* command, const
int fd; int fd;
if (str[0] == '>') if (str[0] == '>')
{ {
if (access(path, F_OK))
dprintf(2, "zzsh: no such file or directory: %s\n", path);
else if (access(path, R_OK))
dprintf(2, "zzsh: permission denied: %s\n", path);
if (nb_symbols == 1) if (nb_symbols == 1)
fd = open(path, O_TRUNC | O_CREAT | O_WRONLY, 0644); fd = open(path, O_TRUNC | O_CREAT | O_WRONLY, 0644);
else else
fd = open(path, O_APPEND | O_CREAT | O_WRONLY, 0644); fd = open(path, O_APPEND | O_CREAT | O_WRONLY, 0644);
if (command->input[0] > 2) if (command->output[0] > 2)
close(command->input[0]); close(command->output[0]);
if (fd == -1) if (fd == -1)
{
dprintf(2, "zzsh: permission denied: %s\n", path);
fd = -2; fd = -2;
command->input[0] = fd; }
command->output[0] = fd;
} }
else else
{ {
if (access(path, F_OK)) if (access(path, F_OK))
dprintf(2, "zzsh: no such file or directory: %s\n", path); dprintf(2, "zzsh: no such file or directory: %s\n", path);
else if (access(path, R_OK)) else if (access(path, R_OK))
dprintf(2, "zzsh: permission denied\n"); dprintf(2, "zzsh: permission denied: %s\n", path);
if (nb_symbols == 1) if (nb_symbols == 1)
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
else else