aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/fs/win32.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index 0280b3f0..b6ea25e4 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -9,6 +9,15 @@ local cfg = require("luarocks.cfg")
9local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
10local util = require("luarocks.util") 10local util = require("luarocks.util")
11 11
12-- Monkey patch io.popen and os.execute to make sure quoting
13-- works as expected.
14-- See http://lua-users.org/lists/lua-l/2013-11/msg00367.html
15local _prefix = "type NUL && "
16local _popen, _execute = io.popen, os.execute
17io.popen = function(cmd, ...) return _popen(_prefix..cmd, ...) end
18os.execute = function(cmd, ...) return _execute(_prefix..cmd, ...) end
19
20
12--- Annotate command string for quiet execution. 21--- Annotate command string for quiet execution.
13-- @param cmd string: A command-line string. 22-- @param cmd string: A command-line string.
14-- @return string: The command-line, with silencing annotation. 23-- @return string: The command-line, with silencing annotation.
@@ -173,3 +182,36 @@ function replace_file(old_file, new_file)
173 return os.rename(new_file, old_file) 182 return os.rename(new_file, old_file)
174end 183end
175 184
185--- Test is file/dir is writable.
186-- Warning: testing if a file/dir is writable does not guarantee
187-- that it will remain writable and therefore it is no replacement
188-- for checking the result of subsequent operations.
189-- @param file string: filename to test
190-- @return boolean: true if file exists, false otherwise.
191function is_writable(file)
192 assert(file)
193 file = dir.normalize(file)
194 local result
195 local tmpname = 'tmpluarockstestwritable.deleteme'
196 if fs.is_dir(file) then
197 local file2 = dir.path(file, tmpname)
198 local fh = io.open(file2, 'wb')
199 result = fh ~= nil
200 if fh then fh:close() end
201 if result then
202 -- the above test might give a false positive when writing to
203 -- c:\program files\ because of VirtualStore redirection on Vista and up
204 -- So get a directory listing and check whether it's really there
205 local pipe = io.popen("dir "..fs.Q(file))
206 local dir_list = pipe:read("*a")
207 pipe:close()
208 result = (nil ~= string.find(dir_list, tmpname, 1, true))
209 end
210 os.remove(file2)
211 else
212 local fh = io.open(file, 'r+b')
213 result = fh ~= nil
214 if fh then fh:close() end
215 end
216 return result
217end