8000 Error if --workdir flag points somewhere that doesn't exist or is not… by jordansissel · Pull Request #1959 · jordansissel/fpm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Error if --workdir flag points somewhere that doesn't exist or is not… #1959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
10 changes: 10 additions & 0 deletions lib/fpm/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}")
Expand Down
21 changes: 21 additions & 0 deletions spec/fpm/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }

Expand Down
0