From 18ed68c91646c20ae9bc21d0fe378898caf3c506 Mon Sep 17 00:00:00 2001 From: Evgeny Shulgin Date: Wed, 4 Oct 2017 10:52:22 -0700 Subject: Patches now can create a new files from /dev/null (#692) --- src/luarocks/tools/patch.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua index 44d00ef8..f1a14578 100644 --- a/src/luarocks/tools/patch.lua +++ b/src/luarocks/tools/patch.lua @@ -84,6 +84,13 @@ local function file_copy(src, dest) return true end +local function overwrite_file(filename) + local fh = io.open(filename, "w+") + if not fh then return false end + fh:close() + return true +end + local function string_as_file(s) return { at = 0, @@ -565,7 +572,12 @@ function patch.apply_patch(the_patch, strip) local all_ok = true local total = #the_patch.source for fileno, filename in ipairs(the_patch.source) do - filename = strip_dirs(filename, strip) + if filename == "/dev/null" then + filename = strip_dirs(the_patch.target[fileno], strip) + assert(overwrite_file(filename)) + else + filename = strip_dirs(filename, strip) + end local continue local f2patch = filename if not exists(f2patch) then -- cgit v1.2.3-55-g6feb