From aefb0b8c359f6613316dcbc4cf07b710fd265d81 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Fri, 24 Apr 2020 23:22:11 +0200
Subject: [PATCH] scripts/copy_output.lua: delete images from OpenWrt dir after
 copying them

We don't move the images directly, as multiple images of the same device
may have the same source image (on x86), but only delete them after a
whole device has been handled (multiple devices using the same images
must be handled using aliases or manifest aliases instead).
---
 scripts/copy_output.lua | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/scripts/copy_output.lua b/scripts/copy_output.lua
index 7b52f4f2d..78300aa79 100755
--- a/scripts/copy_output.lua
+++ b/scripts/copy_output.lua
@@ -31,6 +31,12 @@ mkdir(env.GLUON_IMAGEDIR..'/other')
 lib.include(target)
 
 
+local function image_source(image)
+	return string.format(
+		'openwrt/bin/targets/%s/openwrt-%s-%s%s%s',
+		bindir, openwrt_target, image.name, image.in_suffix, image.extension)
+end
+
 local function clean(image, name)
 	local dir, file = image:dest_name(name, '\0', '\0')
 	lib.exec {'rm', '-f', dir..'/'..file}
@@ -41,8 +47,7 @@ for _, images in pairs(lib.images) do
 		clean(image, image.image)
 
 		local destdir, destname = image:dest_name(image.image)
-		local source = string.format('openwrt/bin/targets/%s/openwrt-%s-%s%s%s',
-			bindir, openwrt_target, image.name, image.in_suffix, image.extension)
+		local source = image_source(image)
 
 		lib.exec {'cp', source, destdir..'/'..destname}
 
@@ -53,6 +58,11 @@ for _, images in pairs(lib.images) do
 			lib.exec {'ln', '-s', destname, destdir..'/'..aliasname}
 		end
 	end
+
+	for _, image in ipairs(images) do
+		local source = image_source(image)
+		lib.exec {'rm', '-f', source}
+	end
 end
 
 
-- 
GitLab