aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-07-22 22:42:16 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-23 08:19:21 -0300
commit8a2516cd3f7a0145098bd13de646f7984a76269d (patch)
tree09b4da202ca5c365f5f07b014e14d7d40424b994 /src
parentc212c884ff4be5d97d675e2390c6db47e18d6f8d (diff)
downloadluarocks-8a2516cd3f7a0145098bd13de646f7984a76269d.tar.gz
luarocks-8a2516cd3f7a0145098bd13de646f7984a76269d.tar.bz2
luarocks-8a2516cd3f7a0145098bd13de646f7984a76269d.zip
fs: make zip/unzip/gunzip/bunzip2 respect `nil,err` protocol
See #850.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/fs/unix/tools.lua22
-rw-r--r--src/luarocks/fs/win32/tools.lua20
2 files changed, 31 insertions, 11 deletions
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index ca7dc6ad..e6be9266 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -123,17 +123,25 @@ end
123-- @param zipfile string: pathname of .zip archive to be created. 123-- @param zipfile string: pathname of .zip archive to be created.
124-- @param ... Filenames to be stored in the archive are given as 124-- @param ... Filenames to be stored in the archive are given as
125-- additional arguments. 125-- additional arguments.
126-- @return boolean: true on success, false on failure. 126-- @return boolean: true on success, nil and error message on failure.
127function tools.zip(zipfile, ...) 127function tools.zip(zipfile, ...)
128 return fs.execute(vars.ZIP.." -r", zipfile, ...) 128 if fs.execute_quiet(vars.ZIP.." -r", zipfile, ...) then
129 return true
130 else
131 return nil, "failed compressing " .. zipfile
132 end
129end 133end
130 134
131--- Uncompress files from a .zip archive. 135--- Uncompress files from a .zip archive.
132-- @param zipfile string: pathname of .zip archive to be extracted. 136-- @param zipfile string: pathname of .zip archive to be extracted.
133-- @return boolean: true on success, false on failure. 137-- @return boolean: true on success, nil and error message on failure.
134function tools.unzip(zipfile) 138function tools.unzip(zipfile)
135 assert(zipfile) 139 assert(zipfile)
136 return fs.execute_quiet(vars.UNZIP, zipfile) 140 if fs.execute_quiet(vars.UNZIP, zipfile) then
141 return true
142 else
143 return nil, "failed extracting " .. zipfile
144 end
137end 145end
138 146
139local function uncompress(default_ext, program, infile, outfile) 147local function uncompress(default_ext, program, infile, outfile)
@@ -142,7 +150,11 @@ local function uncompress(default_ext, program, infile, outfile)
142 if not outfile then 150 if not outfile then
143 outfile = infile:gsub("%."..default_ext.."$", "") 151 outfile = infile:gsub("%."..default_ext.."$", "")
144 end 152 end
145 return fs.execute(fs.Q(program).." -c "..fs.Q(infile).." > "..fs.Q(outfile)) 153 if fs.execute(fs.Q(program).." -c "..fs.Q(infile).." > "..fs.Q(outfile)) then
154 return true
155 else
156 return nil, "failed extracting " .. infile
157 end
146end 158end
147 159
148--- Uncompresses a .gz file. 160--- Uncompresses a .gz file.
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index f5e2ea2e..7e0d10f4 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -135,17 +135,25 @@ end
135-- @param zipfile string: pathname of .zip archive to be created. 135-- @param zipfile string: pathname of .zip archive to be created.
136-- @param ... Filenames to be stored in the archive are given as 136-- @param ... Filenames to be stored in the archive are given as
137-- additional arguments. 137-- additional arguments.
138-- @return boolean: true on success, false on failure. 138-- @return boolean: true on success, nil and error message on failure.
139function tools.zip(zipfile, ...) 139function tools.zip(zipfile, ...)
140 return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa a -tzip", zipfile, ...) 140 if fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa a -tzip", zipfile, ...) then
141 return true
142 else
143 return nil, "failed compressing " .. zipfile
144 end
141end 145end
142 146
143--- Uncompress files from a .zip archive. 147--- Uncompress files from a .zip archive.
144-- @param zipfile string: pathname of .zip archive to be extracted. 148-- @param zipfile string: pathname of .zip archive to be extracted.
145-- @return boolean: true on success, false on failure. 149-- @return boolean: true on success, nil and error message on failure.
146function tools.unzip(zipfile) 150function tools.unzip(zipfile)
147 assert(zipfile) 151 assert(zipfile)
148 return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", zipfile) 152 if fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", zipfile) then
153 return true
154 else
155 return nil, "failed extracting " .. zipfile
156 end
149end 157end
150 158
151local function sevenz(default_ext, infile, outfile) 159local function sevenz(default_ext, infile, outfile)
@@ -160,7 +168,7 @@ local function sevenz(default_ext, infile, outfile)
160 local cmdline = fs.Q(vars.SEVENZ).." -aoa -t* -o"..fs.Q(outdir).." x "..fs.Q(infile) 168 local cmdline = fs.Q(vars.SEVENZ).." -aoa -t* -o"..fs.Q(outdir).." x "..fs.Q(infile)
161 local ok, err = fs.execute_quiet(cmdline) 169 local ok, err = fs.execute_quiet(cmdline)
162 if not ok then 170 if not ok then
163 return nil, err 171 return nil, "failed extracting " .. infile
164 end 172 end
165 173
166 if outfile then 174 if outfile then
@@ -168,7 +176,7 @@ local function sevenz(default_ext, infile, outfile)
168 dropext = fs.absolute_name(dropext) 176 dropext = fs.absolute_name(dropext)
169 ok, err = os.rename(dropext, outfile) 177 ok, err = os.rename(dropext, outfile)
170 if not ok then 178 if not ok then
171 return nil, err 179 return nil, "failed creating new file " .. outfile
172 end 180 end
173 end 181 end
174 182