build: clean up stale files from a previous build when installing a package build...
authorFelix Fietkau <nbd@openwrt.org>
Wed, 29 May 2013 10:31:45 +0000 (10:31 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Wed, 29 May 2013 10:31:45 +0000 (10:31 +0000)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
SVN-Revision: 36755

include/package.mk
scripts/clean-package.sh [new file with mode: 0755]

index 99d2dd2..a4f353b 100644 (file)
@@ -171,6 +171,11 @@ define Build/DefaultTargets
        $(foreach hook,$(Hooks/InstallDev/Post),\
                $(call $(hook),$(TMP_DIR)/stage-$(PKG_NAME),$(TMP_DIR)/stage-$(PKG_NAME)/host)$(sep)\
        )
+       if [ -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) ]; then \
+               $(SCRIPT_DIR)/clean-package.sh \
+                       "$(STAGING_DIR)/packages/$(STAGING_FILES_LIST)" \
+                       "$(STAGING_DIR)"; \
+       fi
        if [ -d $(TMP_DIR)/stage-$(PKG_NAME) ]; then \
                (cd $(TMP_DIR)/stage-$(PKG_NAME); find ./ > $(TMP_DIR)/stage-$(PKG_NAME).files); \
                $(call locked, \
diff --git a/scripts/clean-package.sh b/scripts/clean-package.sh
new file mode 100755 (executable)
index 0000000..d1a2578
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+[ -n "$1" -a -n "$2" ] || {
+       echo "Usage: $0 <file> <directory>"
+       exit 1
+}
+[ -f "$1" -a -d "$2" ] || {
+       echo "File/directory not found"
+       exit 1
+}
+cat "$1" | (
+       cd "$2"
+       while read entry; do
+               [ -n "$entry" ] || break
+               [ -f "$entry" ] && rm -f $entry
+       done
+)
+cat "$1" | (
+       cd "$2"
+       while read entry; do
+               [ -n "$entry" ] || break
+               [ -d "$entry" ] && rmdir "$entry" > /dev/null 2>&1
+       done
+)
+true