]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
naoki: Add support for exclude patterns in filelists.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 1 Oct 2010 21:16:11 +0000 (23:16 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 1 Oct 2010 21:16:11 +0000 (23:16 +0200)
tools/functions-lists
tools/packager

index c44fd728e0260a1d6d5ef9653c996fdddb249da7..d8152d48718fb9a49dd3967a4df26f2af418b479 100644 (file)
@@ -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
+}
index 3bb80b1032143730044911b1bb9ed46f2df48f24..67e91b11513525787959ecce7d1eb8cb30c8e81b 100755 (executable)
@@ -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} && \