From fbd857e1a0b2aae5beb3875427612e41bf67b35e Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 19 Mar 2021 17:13:34 -0300 Subject: pack: check that directory inside archive actually exists --- spec/fixtures/bad_pack-0.1-1.rockspec | 19 +++++++++++++++++++ spec/pack_spec.lua | 6 ++++++ src/luarocks/pack.lua | 8 +++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/bad_pack-0.1-1.rockspec diff --git a/spec/fixtures/bad_pack-0.1-1.rockspec b/spec/fixtures/bad_pack-0.1-1.rockspec new file mode 100644 index 00000000..23934244 --- /dev/null +++ b/spec/fixtures/bad_pack-0.1-1.rockspec @@ -0,0 +1,19 @@ +rockspec_format = "3.0" +package = "bad_pack" +version = "0.1-1" +source = { + url = "http://localhost:8080/file/busted_project-0.1.tar.gz", + dir = "invalid_dir", +} +description = { + summary = "A project that uses Busted tests", +} +build = { + type = "builtin", + modules = { + sum = "sum.lua", + } +} +test = { + type = "busted", +} diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 0790c801..55071839 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -80,6 +80,12 @@ describe("luarocks pack #integration", function() assert.is_truthy(lfs.attributes("a_rock-1.0-1.src.rock")) end) + it("fails packing a rockspec into a .src.rock dir if doesn't exist", function() + local output = run.luarocks("pack " .. testing_paths.fixtures_dir .. "/bad_pack-0.1-1.rockspec") + assert.match("Directory invalid_dir not found", output) + assert.is_falsy(lfs.attributes("bad_pack-0.1-1.src.rock")) + end) + describe("namespaced dependencies", function() it("can pack rockspec with namespaced dependencies", function() finally(function() diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 34268475..5d70a854 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -35,7 +35,13 @@ function pack.pack_source_rock(rockspec_file) local name_version = rockspec.name .. "-" .. rockspec.version local rock_file = fs.absolute_name(name_version .. ".src.rock") - local source_file, source_dir = fetch.fetch_sources(rockspec, false) + local temp_dir, err = fs.make_temp_dir("pack-"..name_version) + if not temp_dir then + return nil, "Failed creating temporary directory: "..err + end + util.schedule_function(fs.delete, temp_dir) + + local source_file, source_dir = fetch.fetch_sources(rockspec, true, temp_dir) if not source_file then return nil, source_dir end -- cgit v1.2.3-55-g6feb