Permalink
Browse files

- Abort and notify the user if the package is to be written to a

  location (parent directory) that does not exist. (#244)
  • Loading branch information...
jordansissel committed Aug 25, 2012
1 parent 872183b commit e1f29462fe041e3cfbf5bee3833d8df0022ad8b7
Showing with 23 additions and 2 deletions.
  1. +3 −0 lib/fpm/command.rb
  2. +16 −0 lib/fpm/package.rb
  3. +1 −2 lib/fpm/package/deb.rb
  4. +1 −0 lib/fpm/package/dir.rb
  5. +1 −0 lib/fpm/package/rpm.rb
  6. +1 −0 lib/fpm/package/tar.rb
View
@@ -353,6 +353,9 @@ def execute
rescue FPM::Package::FileAlreadyExists => e
@logger.fatal(e.message)
return 1
+ rescue FPM::Package::ParentDirectoryMissing => e
+ @logger.fatal(e.message)
+ return 1
end
return 0
View
@@ -25,6 +25,14 @@ def to_s
end # def to_s
end # class FileAlreadyExists
+ # This class is raised when you try to output a package to a path
+ # whose containing directory does not exist.
+ class ParentDirectoryMissing < StandardError
+ def to_s
+ return "Parent directory does not exist: #{File.dirname(super)} - cannot write to #{super}"
+ end # def to_s
+ end # class ParentDirectoryMissing
+
# The name of this package
attr_accessor :name
@@ -487,6 +495,14 @@ def script(script_name)
end
end # def script
+ def output_check(output_path)
+ # Abort if the target path already exists.
+ raise FileAlreadyExists.new(output_path) if File.exists?(output_path)
+ if !File.directory?(File.dirname(output_path))
+ raise ParentDirectoryMissing.new(output_path)
+ end
+ end # def output_path
+
# General public API
public(:type, :initialize, :convert, :input, :output, :to_s, :cleanup, :files,
:version, :script)
View
@@ -225,8 +225,7 @@ def extract_files(package)
end # def extract_files
def output(output_path)
- # Abort if the target path already exists.
- raise FileAlreadyExists.new(output_path) if File.exists?(output_path)
+ output_check(output_path)
# create 'debian-binary' file, required to make a valid debian package
File.write(build_path("debian-binary"), "2.0\n")
View
@@ -50,6 +50,7 @@ def input(path)
# Output this package to the given directory.
def output(dir)
+ output_check(output_path)
dir = File.expand_path(dir)
::Dir.chdir(staging_path) do
@logger["method"] = "output"
View
@@ -173,6 +173,7 @@ def input(path)
end # def input
def output(output_path)
+ output_check(output_path)
%w(BUILD RPMS SRPMS SOURCES SPECS).each { |d| FileUtils.mkdir_p(build_path(d)) }
args = ["rpmbuild", "-bb",
"--define", "buildroot #{build_path}/BUILD",
View
@@ -47,6 +47,7 @@ def input(input_path)
# If the output path ends predictably (like in .tar.gz) it will try to obey
# the compression type.
def output(output_path)
+ output_check(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 e1f2946

Please sign in to comment.