Permalink
Browse files

- Make the decision for symlink, directory, or file copy in Ruby, not

  the rpmbuild spec %install shell.
  • Loading branch information...
1 parent a412708 commit 4a189980164fc96c444168ecfa3567b37fbb74bb @jordansissel committed Dec 7, 2012
Showing with 18 additions and 10 deletions.
  1. +5 −1 spec/fpm/package/rpm_spec.rb
  2. +13 −9 templates/rpm.erb
@@ -60,6 +60,8 @@
describe "#templating" do
context "default user and group" do
before :all do
+ FileUtils.mkdir_p(subject.staging_path(File.dirname(__FILE__)))
+ FileUtils.cp(__FILE__, subject.staging_path(__FILE__))
# set the list of files for this RPM
def subject.files; [__FILE__]; end
@@ -82,6 +84,9 @@ def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
subject.attributes[:rpm_user] = "some_user"
subject.attributes[:rpm_group] = "some_group"
+ FileUtils.mkdir_p(subject.staging_path(File.dirname(__FILE__)))
+ FileUtils.cp(__FILE__, subject.staging_path(__FILE__))
+
# set the list of files for this RPM
def subject.files; [__FILE__]; end
def subject.rpmspec; @rpmspec; end
@@ -123,7 +128,6 @@ def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
subject.scripts[:before_remove] = "example before_remove"
subject.scripts[:after_remove] = "example after_remove"
- p :before_target => @target
# Write the rpm out
subject.output(@target)
View
@@ -75,16 +75,20 @@ Obsoletes: <%= repl %>
%install
<% files.each do |path| -%>
-<% source = Shellwords.shellescape(File.join(staging_path, path)).gsub("%", "%%") -%>
+<% source = File.join(staging_path, path) -%>
+<% source_safe = Shellwords.shellescape(source).gsub("%", "%%") -%>
<% # Copy to the build_path/BUILD/ to make rpmbuild happy -%>
-<% target = Shellwords.shellescape(File.join(build_path, build_sub_dir, path)).gsub("%", "%%") -%>
-<% dir = File.dirname(target) %>
-mkdir -p <%= dir %>
-if [ -f <%= source %> ] || [ -h <%= source %> ] ; then
- cp -d <%= source %> <%= target %>
-elif [ -d <%= source %> ] ; then
- mkdir <%= target %>
-fi
+<% target_safe = Shellwords.shellescape(File.join(build_path, build_sub_dir, path)).gsub("%", "%%") -%>
+<% st = File.lstat(source) -%>
+<% dir = File.dirname(target_safe) -%>
+[ ! -d <%= dir %> ] && mkdir -p <%= dir %>
+<% if st.symlink? -%>
+ln -s <%= File.readlink(source) %> <%= target_safe %>
+<% elsif st.directory? -%>
+mkdir <%= target_safe %>
+<% else -%>
+cp <%= source_safe %> <%= target_safe %>
+<% end -%>
<% end %>
%clean

0 comments on commit 4a18998

Please sign in to comment.