Forced-removing of a non-existing directory breaks the build.
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Tue Jan 20 20:10:50 2009 +0000 (2009-01-20)
changeset 1148081205fd3790
parent 1147 86930cd9340a
child 1149 df32ef8825f9
Forced-removing of a non-existing directory breaks the build.
Noticed by "Andy Johnson" <ajohnson@aecno.com>, who provided a patch that I adapted.

/trunk/scripts/functions | 13 10 3 0 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
scripts/functions
     1.1 --- a/scripts/functions	Tue Jan 20 19:05:52 2009 +0000
     1.2 +++ b/scripts/functions	Tue Jan 20 20:10:50 2009 +0000
     1.3 @@ -242,11 +242,18 @@
     1.4      return 0
     1.5  }
     1.6  
     1.7 -# Removes one or more directories, even if it is read-only
     1.8 +# Removes one or more directories, even if it is read-only, or its parent is
     1.9  # Usage: CT_DoForceRmdir dir [...]
    1.10  CT_DoForceRmdir() {
    1.11 -    CT_DoExecLog ALL chmod -R u+w "${@}"
    1.12 -    CT_DoExecLog ALL rm -rf "${@}"
    1.13 +    local dir
    1.14 +    local mode
    1.15 +    for dir in "${@}"; do
    1.16 +        [ -d "${dir}" ] || continue
    1.17 +        mode="$(stat -c '%a' "${dir}")"
    1.18 +        CT_DoExecLog ALL chmod -R u+w "$(dirname "${dir}")"
    1.19 +        CT_DoExecLog ALL rm -rf "${dir}"
    1.20 +        CT_DoExecLog ALL chmod -R ${mode} "$(dirname "${dir}")"
    1.21 +    done
    1.22  }
    1.23  
    1.24  # Echoes the specified string on stdout until the pipe breaks.