Skip to content

Commit

Permalink
Auto add directories for rpm
Browse files Browse the repository at this point in the history
  • Loading branch information
r4um committed Apr 17, 2013
1 parent 94cd1af commit 3925c1b
Show file tree
Hide file tree
Showing 4 changed files with 14,550 additions and 11 deletions.
5 changes: 4 additions & 1 deletion lib/fpm/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,11 @@ def files
.collect { |path| path[staging_path.length + 1.. -1] }
end # def files

def template_dir
File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "templates"))
end

def template(path)
template_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "templates"))
template_path = File.join(template_dir, path)
template_code = File.read(template_path)
@logger.info("Reading template", :path => template_path)
Expand Down
28 changes: 28 additions & 0 deletions lib/fpm/package/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class FPM::Package::RPM < FPM::Package

option "--sign", :flag, "Pass --sign to rpmbuild"

option "--auto-add-directories", :flag, "Auto add directories not part of filesystem"

private

def rpm_file_entry(file)
Expand Down Expand Up @@ -265,6 +267,32 @@ def output(output_path)

args += ["--sign"] if attributes[:rpm_sign?]

if attributes[:rpm_auto_add_directories?]
fs_dirs_list = File.join(template_dir, "rpm", "filesystem_list")
fs_dirs = File.readlines(fs_dirs_list).reject { |x| x =~ /^\s*#/}.map { |x| x.chomp }

Find.find(staging_path) do |path|
next if path == staging_path
if File.directory? path
add_path = path.gsub(/^#{staging_path}/,'')
self.directories << add_path if not fs_dirs.include? add_path
end
end
else
self.directories = self.directories.map { |x| File.join(self.prefix, x) }
alldirs = []
self.directories.each do |path|
Find.find(File.join(staging_path, path)) do |subpath|
if File.directory? subpath
alldirs << subpath.gsub(/^#{staging_path}/, '')
end
end
end
self.directories = alldirs
end

self.config_files = self.config_files.map { |x| File.join(self.prefix, x) }

(attributes[:rpm_rpmbuild_define] or []).each do |define|
args += ["--define", define]
end
Expand Down
14 changes: 4 additions & 10 deletions templates/rpm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,11 @@ 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) <%= File.join(prefix, path) %>
%config(noreplace) <%= path %>
<% end -%>
<% subdirs = [] -%>
<%# list directories %>
<% directories.each do |path| -%>
%dir <%= rpm_file_entry(File.join(prefix, path)) %>
<%# We need to include hidden directories, but exclude . and .. -%>
<% ::Dir.glob("#{path}/**/*/", File::FNM_DOTMATCH) do |subdir| -%>
<% next if File.basename(subdir) =~ /^\.+$/ -%>
%dir <%= rpm_file_entry(File.join(prefix, subdir)) %>
<% subdirs << subdir -%>
<% end -%>
%dir <%= rpm_file_entry(path) %>
<% end -%>
<%# list only files, not directories? -%>
<%=
Expand All @@ -140,7 +134,7 @@ cp <%= source_safe %> <%= target_safe %>
# Replace % with [%] to make rpm not expand macros
files.collect { |f| "/#{f}" } \
.reject { |f| config_files.include?(f) } \
.reject { |f| subdirs.include?("#{f}/") } \
.reject { |f| directories.include?(f) } \
.collect { |f| f[/\s/] and "\"#{f}\"" or f } \
.collect { |f| f.gsub("[", "[\\[]") } \
.collect { |f| f.gsub("*", "[*]") } \
Expand Down
Loading

0 comments on commit 3925c1b

Please sign in to comment.