From a4dc14dba4f13027684e456b6a21326dfc1bc3c5 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 1 Dec 2018 14:16:39 -0800 Subject: Consider it success if DoForceRmdir removes only the content Fixes #929. Signed-off-by: Alexey Neyman diff --git a/config/configure.in.in b/config/configure.in.in index f483f3b..a9bb8ad 100644 --- a/config/configure.in.in +++ b/config/configure.in.in @@ -9,12 +9,6 @@ config CONFIGURE_has_wget config CONFIGURE_has_curl @KCONFIG_curl@ -config CONFIGURE_has_stat_flavor_BSD - @KCONFIG_stat_flavor_BSD@ - -config CONFIGURE_has_stat_flavor_GNU - @KCONFIG_stat_flavor_GNU@ - config CONFIGURE_has_make_3_81_or_newer @KCONFIG_make_3_81_or_newer@ diff --git a/configure.ac b/configure.ac index 3f8e954..5fd69a7 100644 --- a/configure.ac +++ b/configure.ac @@ -138,8 +138,6 @@ AC_CHECK_PROGS([curl], [curl]) CTNG_SET_KCONFIG_OPTION([curl]) AC_SUBST([curl]) -CTNG_PROG_STAT - CTNG_CPU_COUNT CTNG_PATH_TOOL_REQ([PATCH], [gpatch patch], [patch]) diff --git a/m4/ctng_prog_stat.m4 b/m4/ctng_prog_stat.m4 deleted file mode 100644 index 8a0b26a..0000000 --- a/m4/ctng_prog_stat.m4 +++ /dev/null @@ -1,35 +0,0 @@ -# Check that stat(1) is present and determine the syntax for the format -# string (BSD or GNU). Defines ac_cv_stat_flavor to either GNU or BSD; -# and evaluates either IF-GNU or IF-BSD expression. -# CTNG_PROG_STAT([IF-GNU], [IF-BSD]) -AC_DEFUN([CTNG_PROG_STAT_FORMAT], - [AC_CACHE_CHECK([whether stat takes GNU or BSD format], - [ctng_cv_stat_flavor], - [touch conftest - chmod 642 conftest - attr_bsd=$(stat -f '%Lp' conftest 2>conftest.stderr.bsd) - CTNG_MSG_LOG_ENVVAR([attr_bsd], [stat -f output]) - CTNG_MSG_LOG_FILE([conftest.stderr.bsd]) - attr_gnu=$(stat -c '%a' conftest 2>conftest.stderr.gnu) - CTNG_MSG_LOG_ENVVAR([attr_gnu], [stat -c output]) - CTNG_MSG_LOG_FILE([conftest.stderr.gnu]) - rm -f conftest conftest.stderr.* - AS_IF([test "$attr_bsd" = "642"], - [ctng_cv_stat_flavor=BSD], - [test "$attr_gnu" = "642"], - [ctng_cv_stat_flavor=GNU], - [ctng_cv_stat_flavor=unknown])]) - AS_IF([test "$ctng_cv_stat_flavor" = "GNU" ], [$1], - [test "$ctng_cv_stat_flavor" = "BSD" ], [$2], - [AC_MSG_ERROR([cannot determine stat(1) format option])]) - ]) - -AC_DEFUN([CTNG_PROG_STAT], - [AX_REQUIRE_DEFINED([CTNG_CHECK_PROGS_REQ]) - CTNG_CHECK_PROGS_REQ([stat], [stat]) - CTNG_PROG_STAT_FORMAT( - [CTNG_SET_KCONFIG_OPTION([stat_flavor_GNU], [y]) - CTNG_SET_KCONFIG_OPTION([stat_flavor_BSD])], - [CTNG_SET_KCONFIG_OPTION([stat_flavor_BSD], [y]) - CTNG_SET_KCONFIG_OPTION([stat_flavor_GNU])]) - ]) diff --git a/scripts/crosstool-NG.sh b/scripts/crosstool-NG.sh index b60976c..3e888d7 100644 --- a/scripts/crosstool-NG.sh +++ b/scripts/crosstool-NG.sh @@ -253,11 +253,6 @@ if [ "${CT_SAVE_TARBALLS}" = "y" \ CT_SAVE_TARBALLS= fi -# Check now if we can write to the destination directory: -if [ -d "${CT_PREFIX_DIR}" ]; then - CT_TestAndAbort "Destination directory '${CT_PREFIX_DIR}' is not removable" ! -w $(dirname "${CT_PREFIX_DIR}") -fi - # Good, now grab a bit of informations on the system we're being run on, # just in case something goes awok, and it's not our fault: CT_SYS_USER=$(id -un) diff --git a/scripts/functions b/scripts/functions index 6e54582..e93618c 100644 --- a/scripts/functions +++ b/scripts/functions @@ -582,7 +582,8 @@ CT_Popd() { # Create a dir and pushd into it # Usage: CT_mkdir_pushd -CT_mkdir_pushd() { +CT_mkdir_pushd() +{ local dir="${1}" mkdir -p "${dir}" @@ -592,7 +593,8 @@ CT_mkdir_pushd() { # Creates a temporary directory # $1: variable to assign to # Usage: CT_MktempDir foo -CT_MktempDir() { +CT_MktempDir() +{ # Some mktemp do not allow more than 6 Xs eval "$1"=$(mktemp -q -d "${CT_BUILD_DIR}/tmp.XXXXXX") CT_TestOrAbort "Could not make temporary directory" -n "${!1}" -a -d "${!1}" @@ -602,26 +604,29 @@ CT_MktempDir() { # Removes one or more directories, even if it is read-only, or its parent is # Usage: CT_DoForceRmdir dir [...] -CT_DoForceRmdir() { +CT_DoForceRmdir() +{ local dir - local mode + local cnt + for dir in "${@}"; do - [ -d "${dir}" ] || continue - case "${CT_CONFIGURE_has_stat_flavor_GNU},${CT_CONFIGURE_has_stat_flavor_BSD}" in - y,*) - mode="$(stat -c '%a' "$(dirname "${dir}")")" - ;; - *,y) - mode="$(stat -f '%Lp' "$(dirname "${dir}")")" - ;; - *) - CT_Abort "Unknown stat format options" - ;; - esac - CT_DoExecLog ALL chmod u+w "$(dirname "${dir}")" - CT_DoExecLog ALL chmod -R u+w "${dir}" - CT_DoExecLog ALL rm -rf "${dir}" - CT_DoExecLog ALL chmod ${mode} "$(dirname "${dir}")" + [ -e "${dir}" ] || continue + CT_TestOrAbort "Cannot remove '${dir}': not a directory" -d "${dir}" + CT_DoExecLog ALL chmod -R u+w "${dir}" || :; + if CT_DoExecLog ALL rm -rf "${dir}"; then + continue + fi + # If we succeeded in removing the whole directory, good. If not, + # but only the top level directory remains - it is fine, too, because + # this function is used to remove the directories that are going to be + # re-created. Hence, verify we at least succeeded in verifying the + # contents of this directory. + if [ -d "${dir}" ]; then + cnt=$(ls -a "${dir}" | { grep -v '^\.\{1,2\}$' || :; } | wc -l) + if [ "${cnt}" != "0" ]; then + CT_Abort "Failed to remove '${dir}'" + fi + fi done } @@ -630,7 +635,8 @@ CT_DoForceRmdir() { # $1: path to add # $2: add as 'first' or 'last' path, 'first' is assumed if $2 is empty # Usage CT_SetLibPath /some/where/lib [first|last] -CT_SetLibPath() { +CT_SetLibPath() +{ local path="$1" local pos="$2" -- cgit v0.10.2-6-g49f6