Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to support --rpm-use-file-permissions #377

Merged
merged 1 commit into from Mar 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/fpm/package/rpm.rb
Expand Up @@ -28,6 +28,9 @@ class FPM::Package::RPM < FPM::Package
"bzip2" => "w9.bzdio"
} unless defined?(COMPRESSION_MAP)

option "--use-file-permissions", :flag,
"Use existing file permissions when defining ownership and modes"

option "--user", "USER",
"Set the user to USER in the %files section.",
:default => 'root' do |value|
Expand Down Expand Up @@ -79,6 +82,19 @@ class FPM::Package::RPM < FPM::Package

private

def output_file_line(file)
if attributes[:rpm_use_file_permissions?]
stat = File.stat( file.gsub(/\"/, '') )
user = Etc.getpwuid(stat.uid).name
group = Etc.getgrgid(stat.gid).name
mode = stat.mode
"%%attr(%o, %s, %s) %s\n" % [ mode & 4095 , user, group, file ]
else
"#{file}\n"
end
end


# Handle any architecture naming conversions.
# For example, debian calls amd64 what redhat calls x86_64, this
# method fixes those types of things.
Expand Down
6 changes: 3 additions & 3 deletions templates/rpm.erb
Expand Up @@ -119,11 +119,11 @@ cp <%= source_safe %> <%= target_safe %>
<% end -%>
<% subdirs = [] -%>
<% directories.each do |path| -%>
%dir <%= File.join(prefix, path) %>
%dir <%= output_file_line(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 <%= File.join(prefix, subdir) %>
%dir <%= output_file_line(File.join(prefix, subdir)) %>
<% subdirs << subdir -%>
<% end -%>
<% end -%>
Expand All @@ -146,7 +146,7 @@ cp <%= source_safe %> <%= target_safe %>
.collect { |f| f.gsub("*", "[*]") } \
.collect { |f| f.gsub("?", "[?]") } \
.collect { |f| f.gsub("%", "[%]") } \
.join("\n")
.map { |f| output_file_line(f) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the .join("\n") was the problem here.

#.collect { |f| File.join(prefix, f) } \
%>

Expand Down