From fa223d4723324a7c09f670e4039eaae65a66328b Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Sun, 13 Nov 2022 20:20:49 -0800 Subject: [PATCH] Error if --workdir flag points somewhere that doesn't exist or is not a directory. Fixes #1938 --- lib/fpm/command.rb | 10 ++++++++++ spec/fpm/command_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/fpm/command.rb b/lib/fpm/command.rb index 115ea5b317..d2c2d78a7a 100644 --- a/lib/fpm/command.rb +++ b/lib/fpm/command.rb @@ -298,6 +298,15 @@ def execute args << "." end + if !File.exists?(workdir) + logger.fatal("Given --workdir=#{workdir} is not a path that exists.") + raise FPM::Package::InvalidArgument, "The given workdir '#{workdir}' does not exist." + end + if !File.directory?(workdir) + logger.fatal("Given --workdir=#{workdir} must be a directory") + raise FPM::Package::InvalidArgument, "The given workdir '#{workdir}' must be a directory." + end + logger.info("Setting workdir", :workdir => workdir) ENV["TMP"] = workdir @@ -578,6 +587,7 @@ def run(run_args) ARGV.unshift(*flags) ARGV.push(*args) + super(run_args) rescue FPM::Package::InvalidArgument => e logger.error("Invalid package argument: #{e}") diff --git a/spec/fpm/command_spec.rb b/spec/fpm/command_spec.rb index 0a5d35af9e..68895a008d 100644 --- a/spec/fpm/command_spec.rb +++ b/spec/fpm/command_spec.rb @@ -26,6 +26,27 @@ describe "--directories" describe "-a | --architecture" + describe "--workdir" do + subject { FPM::Command.new("fpm") } + + context "with an nonexistent path" do + it "should fail aka return nonzero exit" do + args = ["--workdir", "/this/path/should/not/exist", "-s", "rpm", "-t", "empty", "-n", "example"] + insist { subject.run(args) } != 0 + end + end + + context "with a path that is not a directory" do + it "should fail aka return nonzero exit" do + Stud::Temporary.file do |file| + args = ["--workdir", file.path, "-s", "rpm", "-t", "empty", "-n", "example"] + insist { subject.run(args) } != 0 + end + end + end + + end + describe "-v | --version" do subject { FPM::Command.new("fpm") }