From 0063eb6cf8d69da4a9d6a4c7e2741db360e9c81b Mon Sep 17 00:00:00 2001 From: vagrant Date: Mon, 9 Jun 2014 04:45:46 +0000 Subject: [PATCH] naive implementation of rpm %attr directive --- lib/fpm/command.rb | 10 ++++++++++ lib/fpm/package.rb | 5 ++++- lib/fpm/package/rpm.rb | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/fpm/command.rb b/lib/fpm/command.rb index 62b8e3767d..0ddb003207 100644 --- a/lib/fpm/command.rb +++ b/lib/fpm/command.rb @@ -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| diff --git a/lib/fpm/package.rb b/lib/fpm/package.rb index f75ca6c703..e421930c9b 100644 --- a/lib/fpm/package.rb +++ b/lib/fpm/package.rb @@ -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 @@ -172,6 +174,7 @@ def initialize @scripts = {} @config_files = [] @directories = [] + @attrs = {} staging_path build_path @@ -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), diff --git a/lib/fpm/package/rpm.rb b/lib/fpm/package/rpm.rb index ba31402396..efa0b4cf54 100644 --- a/lib/fpm/package/rpm.rb +++ b/lib/fpm/package/rpm.rb @@ -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| @@ -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? # Stat the original filename in the relative staging path ::Dir.chdir(staging_path) do