mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-05 03:10:50 +02:00
fix for $_ when executing $PROMPT_COMMAND; fix for extra line in history after here-document in command substitution
This commit is contained in:
+50
-32
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022-2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -135,10 +135,12 @@ mkdir_builtin (WORD_LIST *list)
|
||||
static int
|
||||
make_path (char *path, int user_mode, int nmode, int parent_mode)
|
||||
{
|
||||
int oumask;
|
||||
mode_t oumask;
|
||||
struct stat sb;
|
||||
char *p, *npath;
|
||||
int tail;
|
||||
|
||||
/* If we don't have to do any work, don't do any work. */
|
||||
if (stat (path, &sb) == 0)
|
||||
{
|
||||
if (S_ISDIR (sb.st_mode) == 0)
|
||||
@@ -166,48 +168,64 @@ make_path (char *path, int user_mode, int nmode, int parent_mode)
|
||||
while (*p == '/')
|
||||
p++;
|
||||
|
||||
while (p = strchr (p, '/'))
|
||||
tail = 0;
|
||||
while (tail == 0)
|
||||
{
|
||||
*p = '\0';
|
||||
if (stat (npath, &sb) != 0)
|
||||
if (*p == '\0')
|
||||
tail = 1;
|
||||
else
|
||||
p = strchr (p, '/');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
else
|
||||
tail = 1;
|
||||
if (mkdir (npath, 0) < 0)
|
||||
{
|
||||
if (mkdir (npath, 0))
|
||||
/* "Each dir operand that names an existing directory shall be
|
||||
ignored without error." */
|
||||
if (errno == EEXIST || errno == EISDIR)
|
||||
{
|
||||
int e = errno;
|
||||
int fail = 0;
|
||||
|
||||
if (stat (npath, &sb) != 0)
|
||||
{
|
||||
fail = 1;
|
||||
builtin_error ("cannot create directory `%s': %s", npath, strerror (e));
|
||||
}
|
||||
else if (e == EEXIST && S_ISDIR (sb.st_mode) == 0)
|
||||
{
|
||||
fail = 1;
|
||||
builtin_error ("`%s': file exists but is not a directory", npath);
|
||||
}
|
||||
if (fail)
|
||||
{
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_error ("cannot create directory `%s': %s", npath, strerror (errno));
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
if (chmod (npath, parent_mode) != 0)
|
||||
{
|
||||
builtin_error ("cannot chmod directory `%s': %s", npath, strerror (errno));
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (S_ISDIR (sb.st_mode) == 0)
|
||||
{
|
||||
builtin_error ("`%s': file exists but is not a directory", npath);
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
*p++ = '/'; /* restore slash */
|
||||
while (*p == '/')
|
||||
if (chmod (npath, (tail == 0) ? parent_mode : nmode) != 0)
|
||||
{
|
||||
builtin_error ("cannot chmod directory `%s': %s", npath, strerror (errno));
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
if (tail == 0)
|
||||
*p++ = '/'; /* restore slash */
|
||||
while (p && *p == '/') /* skip consecutive slashes or trailing slash */
|
||||
p++;
|
||||
}
|
||||
|
||||
/* Create the final directory component. */
|
||||
if (stat (npath, &sb) && mkdir (npath, nmode))
|
||||
{
|
||||
builtin_error ("cannot create directory `%s': %s", npath, strerror (errno));
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user