From f05b0c6935a5f1a32e9c7c15b0998c56f3b17ae4 Mon Sep 17 00:00:00 2001 From: Pranay Kanwar Date: Wed, 17 Apr 2013 21:11:29 +0530 Subject: [PATCH] #413 Fix name for directories and config files --- lib/fpm/package/rpm.rb | 14 ++++++++++++++ templates/rpm.erb | 32 +++++++++----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/fpm/package/rpm.rb b/lib/fpm/package/rpm.rb index 96be48d92d..bcafb6ed42 100644 --- a/lib/fpm/package/rpm.rb +++ b/lib/fpm/package/rpm.rb @@ -86,7 +86,21 @@ class FPM::Package::RPM < FPM::Package private + # Fix path name + # Replace [ with [\[] to make rpm not use globs + # Replace * with [*] to make rpm not use globs + # Replace ? with [?] to make rpm not use globs + # Replace % with [%] to make rpm not expand macros + def rpm_fix_name(name) + name = "\"#{name}\"" if name[/\s/] + name = name.gsub("[", "[\\[]") + name = name.gsub("*", "[*]") + name = name.gsub("?", "[?]") + name = name.gsub("%", "[%]") + end + def rpm_file_entry(file) + file = rpm_fix_name(file) return file unless attributes[:rpm_use_file_permissions?] stat = File.stat( file.gsub(/\"/, '') ) diff --git a/templates/rpm.erb b/templates/rpm.erb index 69eb1ae667..0118ec4eec 100644 --- a/templates/rpm.erb +++ b/templates/rpm.erb @@ -115,35 +115,21 @@ cp <%= source_safe %> <%= target_safe %> %defattr(-,<%= attributes[:rpm_user] %>,<%= attributes[:rpm_group] %>,-) <%# Output config files and then regular files. -%> <% config_files.each do |path| -%> -%config(noreplace) <%= path %> +%config(noreplace) <%= rpm_fix_name(path) %> <% end -%> <%# list directories %> <% directories.each do |path| -%> %dir <%= rpm_file_entry(path) %> <% end -%> <%# list only files, not directories? -%> -<%= - # Reject config files already listed or parent directories, then prefix files - # with "/", then make sure paths with spaces are quoted. I hate rpm so much. - - # 'files' here is the method FPM::Package#files. - # The 'files' section of rpm can be - # Replace [ with [\[] to make rpm not use globs - # Replace * with [*] to make rpm not use globs - # Replace ? with [?] to make rpm not use globs - # Replace % with [%] to make rpm not expand macros - files.collect { |f| "/#{f}" } \ - .reject { |f| config_files.include?(f) } \ - .reject { |f| directories.include?(f) } \ - .collect { |f| f[/\s/] and "\"#{f}\"" or f } \ - .collect { |f| f.gsub("[", "[\\[]") } \ - .collect { |f| f.gsub("*", "[*]") } \ - .collect { |f| f.gsub("?", "[?]") } \ - .collect { |f| f.gsub("%", "[%]") } \ - .map { |f| rpm_file_entry(f) } \ - .join("\n") - #.collect { |f| File.join(prefix, f) } \ -%> +# Reject config files already listed or parent directories, then prefix files +# with "/", then make sure paths with spaces are quoted. I hate rpm so much. +<% files.each do |path| -%> +<% path = "/#{path}" -%> +<% next if config_files.include?(path)-%> +<% next if directories.include?(path)-%> +<%= rpm_file_entry(path) %> +<% end -%> %changelog <%= attributes[:rpm_changelog] %>