Permalink
Browse files

Add -f/--force flag to allow overwriting existing package output path

- fixes #354
- consolidated FileAlreadyExists error into Package class's output_check rather than duplicate it within each package type
  • Loading branch information...
1 parent f59dc32 commit 05dceea5f623d9feac9c27cd046809eaf36ea904 @timsutton timsutton committed Mar 22, 2013
Showing with 9 additions and 4 deletions.
  1. +2 −0 lib/fpm/command.rb
  2. +7 −0 lib/fpm/package.rb
  3. +0 −1 lib/fpm/package/deb.rb
  4. +0 −1 lib/fpm/package/osxpkg.rb
  5. +0 −1 lib/fpm/package/rpm.rb
  6. +0 −1 lib/fpm/package/tar.rb
View
@@ -55,6 +55,8 @@ def help(*args)
"be necessary for all input packages. For example, the 'gem' type will" \
"prefix with your gem directory automatically."
option ["-p", "--package"], "OUTPUT", "The package file path to output."
+ option ["-f", "--force"], :flag, "Force output even if it will overwrite an " \
+ "existing file", :default => false
option ["-n", "--name"], "NAME", "The name to give to the package"
option "--verbose", :flag, "Enable verbose output"
option "--debug", :flag, "Enable debug output"
View
@@ -487,6 +487,13 @@ def output_check(output_path)
if !File.directory?(File.dirname(output_path))
raise ParentDirectoryMissing.new(output_path)
end
+ if File.exists?(output_path)
+ if attributes[:force?]
+ @logger.warn("--force flag given, overwriting package at #{output_path}")
+ else
+ raise FileAlreadyExists.new(output_path)
+ end
+ end
end # def output_path
def provides=(value)
@@ -267,7 +267,6 @@ def extract_files(package)
def output(output_path)
output_check(output_path)
# Abort if the target path already exists.
- raise FileAlreadyExists.new(output_path) if File.exists?(output_path)
# create 'debian-binary' file, required to make a valid debian package
File.write(build_path("debian-binary"), "2.0\n")
@@ -130,7 +130,6 @@ def input(input_path)
# Output a pkgbuild pkg.
def output(output_path)
output_check(output_path)
- raise FileAlreadyExists.new(output_path) if File.exists?(output_path)
temp_info = pkginfo_template_path
@@ -231,7 +231,6 @@ def input(path)
def output(output_path)
output_check(output_path)
- raise FileAlreadyExists.new(output_path) if File.exists?(output_path)
%w(BUILD RPMS SRPMS SOURCES SPECS).each { |d| FileUtils.mkdir_p(build_path(d)) }
args = ["rpmbuild", "-bb"]
@@ -48,7 +48,6 @@ def input(input_path)
# the compression type.
def output(output_path)
output_check(output_path)
- raise FileAlreadyExists.new(output_path) if File.exists?(output_path)
# Unpack the tarball to the staging path
args = ["-cf", output_path, "-C", staging_path, "."]
with(tar_compression_flag(output_path)) do |flag|

0 comments on commit 05dceea

Please sign in to comment.