Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make the --exclude argument work by removing the excluded paths from the staging directory #186

Merged
merged 2 commits into from

4 participants

@cpennington

No description provided.

@jordansissel

Thanks for the patch!

I'll have a ponder about how the api change (Adding #exclude to Package) since I'm not totally sold on that - perhaps there's a better way? This way feels weird. Still, I want to get this functioning again, so even if I can't come up with something that feels a bit smoother I'll merge this as-is, since it looks ok :)

@vStone

I've been testing this patch since I really need to the exclude functionality but I cant seem to get it working

running

fpm -n blah -s dir -t rpm --prefix "/etc/" --exclude '*/.git*' blah

still adds .git folder/files.

Also tested: --exclude ".gitignore" and --exlude "*/.gitignore"

@vStone

Also, fpm fails if you don't use --exclude

@bernd

I was thinking about adding the exclude cleanup of the staging area to Package#convert to avoid adding another method to the Package API. But then we still have to pass the list of excluded files to the package somehow.

@cpennington

The interface that I've been using for exclude is that of Dir.glob, rooted in the prefixed directory. So, to ignore .git, you'd just use --exclude=.git (I don't know if this is a change from the previous implementation)

As for adding exclude cleanup into package#convert, that should work fine. The exclude paths are already added as an attribute to the package (along with all of the other commandline arguments).

fpm failing w/o exclude is no good. I'll fix that up asap.

@cpennington

Actually, while I'm at it, I'll see if I can remove the additional api bit, and roll it into convert.

@jordansissel jordansissel commented on the diff
lib/fpm/command.rb
@@ -273,10 +276,11 @@ def execute
set.call(input, :version)
set.call(input, :architecture)
- input.conflicts += conflicts
- input.dependencies += dependencies
- input.provides += provides
- input.replaces += replaces
+ input.conflicts += @conflicts
@jordansissel Owner

why use the instance variables here? These are available as methods (created by the options like --conflicts)

@jordansissel Owner

I'll merge this pull, but will be reverting the this particular change (ivars instead of methods). Unless I'm missing something, let me know why this change was made, curious! :)

I had issues when trying to use excludes in the same way as conflicts/dependencies/provides/replaces. It may have just been an oversight of mine, honestly, as I'm relatively inexperienced w/ ruby.

@jordansissel Owner

For being inexperienced with ruby, this patch was super awesome. Good work! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jordansissel jordansissel merged commit 0f2da16 into jordansissel:master
@jordansissel

Thanks for this :)

@jordansissel jordansissel referenced this pull request from a commit
@jordansissel - Make file exclusion work again. Fixes #185
  This improves on the patch in #186.
- Add tests to make sure exclude stays working :)
25cc3b1
@prof-milki prof-milki referenced this pull request from a commit in prof-milki/xpm
jls - Make file exclusion work again. Fixes #185
  This improves on the patch in #186.
- Add tests to make sure exclude stays working :)
665d239
@prof-milki prof-milki referenced this pull request from a commit in prof-milki/xpm
@jordansissel - Make file exclusion work again. Fixes #185
  This improves on the patch in #186.
- Add tests to make sure exclude stays working :)
551a70c
@jordansissel jordansissel referenced this pull request from a commit
@jordansissel - Make file exclusion work again. Fixes #185
  This improves on the patch in #186.
- Add tests to make sure exclude stays working :)
3d4aad2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2012
  1. @cpennington
Commits on Mar 27, 2012
  1. @cpennington

    Move exclude functionality into the convert process, and make give it…

    cpennington authored
    … a sensible default of excluding nothing
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 8 deletions.
  1. +12 −8 lib/fpm/command.rb
  2. +25 −0 lib/fpm/package.rb
View
20 lib/fpm/command.rb
@@ -95,9 +95,11 @@ class FPM::Command < Clamp::Command
option ["-e", "--edit"], :flag,
"Edit the package spec before building.", :default => false
option ["-x", "--exclude"], "EXCLUDE_PATTERN",
- "Exclude paths matching pattern (shell wildcard globs valid here)" do |val|
- @exclude_pattern ||= []
- @exclude_pattern << val
+ "Exclude paths matching pattern (shell wildcard globs valid here). " \
+ "Patterns are evaluated relative to the root of the working directory, " \
+ "or the directory specified by -C" do |val|
+ @excludes ||= []
+ @excludes << val
end # -x / --exclude
option "--description", "DESCRIPTION", "Add a description for this package.",
:default => "no description"
@@ -173,6 +175,7 @@ def initialize(*args)
@provides = []
@dependencies = []
@config_files = []
+ @excludes = []
end # def initialize
# Execute this command. See Clamp::Command#execute and Clamp's documentation
@@ -273,10 +276,11 @@ def execute
set.call(input, :version)
set.call(input, :architecture)
- input.conflicts += conflicts
- input.dependencies += dependencies
- input.provides += provides
- input.replaces += replaces
+ input.conflicts += @conflicts
@jordansissel Owner

why use the instance variables here? These are available as methods (created by the options like --conflicts)

@jordansissel Owner

I'll merge this pull, but will be reverting the this particular change (ivars instead of methods). Unless I'm missing something, let me know why this change was made, curious! :)

I had issues when trying to use excludes in the same way as conflicts/dependencies/provides/replaces. It may have just been an oversight of mine, honestly, as I'm relatively inexperienced w/ ruby.

@jordansissel Owner

For being inexperienced with ruby, this patch was super awesome. Good work! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ input.dependencies += @dependencies
+ input.provides += @provides
+ input.replaces += @replaces
+ input.excludes += @excludes
setscript = proc do |scriptname|
path = self.send(scriptname)
@@ -295,7 +299,7 @@ def execute
setscript.call(:after_install)
setscript.call(:before_remove)
setscript.call(:after_remove)
-
+
# Convert to the output type
output = input.convert(output_class)
View
25 lib/fpm/package.rb
@@ -82,6 +82,9 @@ def to_s
# (Not all packages support this)
attr_accessor :replaces
+ # Array of glob patterns to exclude from this package
+ attr_accessor :excludes
+
# a summary or description of the package
attr_accessor :description
@@ -155,6 +158,7 @@ def initialize
@dependencies = []
@scripts = {}
@config_files = []
+ @excludes = []
staging_path
build_path
@@ -170,6 +174,9 @@ def type
# Convert this package to a new package type
def convert(klass)
@logger.info("Converting #{self.type} to #{klass.type}")
+
+ exclude
+
pkg = klass.new
pkg.cleanup_staging # purge any directories that may have been created by klass.new
@@ -311,6 +318,24 @@ def edit_file(path)
end
end # def edit_file
+ def exclude()
+ # This method removes excluded files from the staging_path. Subclasses can
+ # remove the files during the input phase rather than deleting them here
+ if @attributes.include?(:prefix)
+ installdir = staging_path(@attributes[:prefix])
+ else
+ installdir = staging_path
+ end
+
+ @excludes.each do |path|
+ path = File.join(installdir, path)
+ ::Dir.glob(path) do |rmpath|
+ @logger.debug("Removing", :path => rmpath)
+ FileUtils.remove_entry_secure(rmpath)
+ end
+ end
+ end # def exclude
+
class << self
# This method is invoked when subclass occurs.
Something went wrong with that request. Please try again.