From: Michael Tremer Date: Fri, 1 Oct 2010 21:16:11 +0000 (+0200) Subject: naoki: Add support for exclude patterns in filelists. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5e4fc2e25be740198143aa8743f05fe2612f698;p=ipfire-3.x.git naoki: Add support for exclude patterns in filelists. --- diff --git a/tools/functions-lists b/tools/functions-lists index c44fd728e..d8152d487 100644 --- a/tools/functions-lists +++ b/tools/functions-lists @@ -20,3 +20,12 @@ function listmatch() { return 1 } +function sort_by_length() { + local c + local i + for i in $@; do + echo "$(wc -c <<<${i}) ${i}" + done | sort -n -r | while read c i; do + echo "${i}" + done +} diff --git a/tools/packager b/tools/packager index 3bb80b103..67e91b115 100755 --- a/tools/packager +++ b/tools/packager @@ -61,6 +61,7 @@ BUILD_ID="${BUILD_ID}" # Distribution information DISTRO_NAME="${DISTRO_NAME}" DISTRO_EPOCH="${DISTRO_EPOCH}" +DISTRO_VENDOR="${DISTRO_VENDOR}" # Package information PKG_NAME="${PKG_NAME}" @@ -112,20 +113,50 @@ ${CONTROL_POSTUN} EOF } +function find_files() { + local paths=$@ + local file + + for file in $(find ${paths} 2>/dev/null | sort); do + # Remove ${BUILDROOT} + file="${file#${BUILDROOT}}" + + # Remove all leading slashes + while [ "${file:0:1}" = "/" ]; do + file="${file:1:${#file}}" + done + + echo "${file}" + done +} + function __filelist() { local paths + local exclude_paths # Disable globbing set -f local path + local exclude for path in ${PKG_FILES}; do + if [ "${path:0:1}" = "!" ]; then + exclude="1" + path="${path:1:${#path}}" + else + exclude="0" + fi + if [ "${path:0:1}" != "/" ]; then path="/${path}" fi path="${BUILDROOT}${path}" - paths="${paths} ${path}" + if [ "${exclude}" = "0" ]; then + paths="${paths} ${path}" + else + exclude_paths="${exclude_paths} ${path}" + fi done # Enable globbing again @@ -134,16 +165,19 @@ function __filelist() { # If not paths were found take all files [ -z "${paths}" ] && paths="${BUILDROOT}" - for file in $(find ${paths} 2>/dev/null | sort); do - # Remove ${BUILDROOT} - file="${file#${BUILDROOT}}" - - # Remove all leading slashes - while [ "${file:0:1}" = "/" ]; do - file="${file:1:${#file}}" - done + local excludes + if [ -n "${exclude_paths}" ]; then + excludes=$(find_files ${exclude_paths}) + fi - echo "${file}" + for file in $(find_files ${paths}); do + if [ -n "${excludes}" ]; then + if ! listmatch ${file} ${excludes}; then + echo "${file}" + fi + else + echo "${file}" + fi done } @@ -179,11 +213,18 @@ function create_dataimg() { local file # Remove the just copied files + sort_by_length $(<${filelist}) | \ while read file; do [ -z "${file}" ] && continue + if [ -d "${BUILDROOT}/${file}" ]; then + if dir_is_empty ${BUILDROOT}/${file}; then + rm -rf ${BUILDROOT}/${file} + fi + continue + fi rm -rf ${BUILDROOT}/${file} - done < ${filelist} + done # Return the filelist cd ${dir} && \