diff --git a/package/gluon.mk b/package/gluon.mk
index b69caa81f5a6d92a5fe24520cea5a9e8865990d8..0139544e9fcb578eff2db48606e784f990789d5f 100644
--- a/package/gluon.mk
+++ b/package/gluon.mk
@@ -61,14 +61,14 @@ endef
 define GluonSrcDiet
 	rm -rf $(2)
 	$(CP) $(1) $(2)
-ifdef CONFIG_GLUON_MINIFY
-	$(FIND) $(2) -type f | while read src; do \
-		if luasrcdiet --noopt-binequiv -o "$$$$src.o" "$$$$src"; then \
-			chmod $$$$(stat -c%a "$$$$src") "$$$$src.o"; \
-			mv "$$$$src.o" "$$$$src"; \
-		fi; \
+  ifdef CONFIG_GLUON_MINIFY
+	# Use cp + rm instead of mv to preserve destination permissions
+	set -e; $(FIND) $(2) -type f | while read src; do \
+		luasrcdiet --noopt-binequiv -o "$$$$src.tmp" "$$$$src"; \
+		cp "$$$$src.tmp" "$$$$src"; \
+		rm "$$$$src.tmp"; \
 	done
-endif
+  endif
 endef