Skip to content

Commit

Permalink
naive implementation of rpm %attr directive
Browse files Browse the repository at this point in the history
  • Loading branch information
vagrant authored and Leslie I'Anson committed Jun 9, 2014
1 parent ebcaf8a commit 0063eb6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/fpm/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ def execute
input.replaces += replaces
input.config_files += config_files
input.directories += directories

h = {}
attrs.each do | e |

s = e.split(':', 2)
h[s.last] = s.first
end

input.attrs = h


script_errors = []
setscript = proc do |scriptname|
Expand Down
5 changes: 4 additions & 1 deletion lib/fpm/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def to_s
# This is where you'd put rpm, deb, or other specific attributes.
attr_accessor :attributes

attr_accessor :attrs

private

def initialize
Expand Down Expand Up @@ -172,6 +174,7 @@ def initialize
@scripts = {}
@config_files = []
@directories = []
@attrs = {}

staging_path
build_path
Expand All @@ -198,7 +201,7 @@ def convert(klass)
:@architecture, :@category, :@config_files, :@conflicts,
:@dependencies, :@description, :@epoch, :@iteration, :@license, :@maintainer,
:@name, :@provides, :@replaces, :@scripts, :@url, :@vendor, :@version,
:@directories, :@staging_path
:@directories, :@staging_path, :@attrs
]
ivars.each do |ivar|
#@logger.debug("Copying ivar", :ivar => ivar, :value => instance_variable_get(ivar),
Expand Down
16 changes: 15 additions & 1 deletion lib/fpm/package/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class FPM::Package::RPM < FPM::Package
option "--autoreq", :flag, "Enable RPM's AutoReq option"
option "--autoprov", :flag, "Enable RPM's AutoProv option"

option "--attr", "ATTRFILE",
"Set the attribute for a file (%attr).",
:multivalued => true, :attribute_name => :attrs

rpmbuild_filter_from_provides = []
option "--filter-from-provides", "REGEX",
"Set %filter_from_provides to the supplied REGEX." do |filter_from_provides|
Expand Down Expand Up @@ -131,7 +135,17 @@ def rpm_fix_name(name)
def rpm_file_entry(file)
original_file = file
file = rpm_fix_name(file)
return file unless attributes[:rpm_use_file_permissions?]

if !attributes[:rpm_use_file_permissions?]

if attrs[file].nil?
return file
else
return sprintf("%%attr(%s) %s\n", attrs[file], file)
end
end

return sprintf("%%attr(%s) %s\n", attrs[file], file) unless attrs[file].nil?

This comment has been minimized.

Copy link
@clayne

clayne Apr 22, 2015

This section of code was confusing and repetitive when reading it at first to try and figure out what was going on. I vote this to be a cleaner approach:

# If attributes provided, use those, otherwise if rpm-use-file-permissions is false, use rpm defaults.
if !attrs[file].nil?
  return sprintf("%%attr(%s) %s\n", attrs[file], file)
elsif !attributes[:rpm_use_file_permissions?]
  return file
end

Then kill line 148 and let it fall through to the rpm-use-file-permissions true case. Since the attribute check is winning in all cases if it's non-nil, there's no reason to be checking it twice. It's precedence is higher in the overall logic regardless of rpm-use-file-permissions being true or not.

# Stat the original filename in the relative staging path
::Dir.chdir(staging_path) do
Expand Down

0 comments on commit 0063eb6

Please sign in to comment.