Skip to content

Commit

Permalink
#413 Fix name for directories and config files
Browse files Browse the repository at this point in the history
  • Loading branch information
r4um committed Apr 17, 2013
1 parent 3925c1b commit f05b0c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
14 changes: 14 additions & 0 deletions lib/fpm/package/rpm.rb
Expand Up @@ -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(/\"/, '') )
Expand Down
32 changes: 9 additions & 23 deletions templates/rpm.erb
Expand Up @@ -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] %>

0 comments on commit f05b0c6

Please sign in to comment.