From d1a9ef651a67dddd1ec4f3e0d2863a30285ed90e Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Sun, 6 Nov 2022 16:08:48 -0800 Subject: [PATCH] Try have the srpm match the output file name This is for cases like `fpm -p hello.rpm` and it seems like we'd want the srpm named "hello.src.rpm" instead of whatever was generated by rpmbuild. I don't know if this will make things less confusing, but I hope it will make things more predictable :) --- lib/fpm/package/rpm.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/fpm/package/rpm.rb b/lib/fpm/package/rpm.rb index 4d4d70e42f..379404aad3 100644 --- a/lib/fpm/package/rpm.rb +++ b/lib/fpm/package/rpm.rb @@ -580,7 +580,29 @@ def output(output_path) # Copy out the SRPM packages ::Dir["#{build_path}/SRPMS/**/*.rpm"].each do |rpmpath| - FileUtils.cp(rpmpath, File.dirname(output_path)) + # Try to use the same naming scheme if we are specifying a custom output path? + # Replace the .ARCH.EXTENSION with .src.EXTENSION ? + # + # For example, if the output wanted "foo.noarch.rpm" + # then the srpm should be named "foo.src.rpm" + # + # But for the cases where someone asked for a file with just ".rpm" at the end, + # we can also write the srpm as ".src.rpm" + extension_checks = [ + # Try ..rpm ending + Regexp.compile(to_s(".ARCH.EXTENSION$")), + # Try just .rpm ending + Regexp.compile(to_s(".EXTENSION$")) + ] + + extension_checks.each do |re| + if output_path =~ re + filename = File.basename(output_path).gsub(re, to_s(".src.EXTENSION")) + p [ "Copying", rpmpath => filename ] + FileUtils.cp(rpmpath, File.join(File.dirname(output_path), filename)) + break + end + end end end # def output