Skip to content

Commit 2bcdb34

Browse files
authored
Merge pull request #2101 from fourieraudio/more-systemd-file-extensions
Add all valid file extensions for systemd units
2 parents d75e024 + 29075e6 commit 2bcdb34

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

lib/fpm/package/deb.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,17 +542,37 @@ def output(output_path)
542542
raise FPM::InvalidPackageConfiguration, "#{name}: tar is insufficient to support source_date_epoch."
543543
end
544544

545+
systemd_file_extensions = [
546+
".service",
547+
".socket",
548+
".device",
549+
".mount",
550+
".automount",
551+
".swap",
552+
".target",
553+
".path",
554+
".timer",
555+
".slice",
556+
".scope",
557+
]
558+
545559
attributes[:deb_systemd] = []
546560
attributes.fetch(:deb_systemd_list, []).each do |systemd|
547561
name = File.basename(systemd)
548562
extname = File.extname(name)
549563

550564
name_with_extension = if extname.empty?
551565
"#{name}.service"
552-
elsif [".service", ".timer"].include?(extname)
566+
elsif systemd_file_extensions.include?(extname)
553567
name
554568
else
555-
raise FPM::InvalidPackageConfiguration, "Invalid systemd unit file extension: #{extname}. Expected .service or .timer, or no extension."
569+
# Mutating the array is fine as we raise directly after, and the array will be re-initialised next time
570+
# this method is called. If this branch is changed in the future so as not to diverge, care should be
571+
# taken to ensure that this mutated version of the array is only used for generating the error message.
572+
systemd_file_extensions[-1] = systemd_file_extensions[-1].prepend("or ")
573+
possible_extensions_str = systemd_file_extensions.join(", ")
574+
raise FPM::InvalidPackageConfiguration,
575+
"Invalid systemd unit file extension: #{extname}. Expected one of: #{possible_extensions_str}"
556576
end
557577

558578
dest_systemd = staging_path(File.join(attributes[:deb_systemd_path], "#{name_with_extension}"))

0 commit comments

Comments
 (0)