diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2013-11-28 21:06:40 +0100 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2013-11-28 21:06:40 +0100 |
commit | 4c650b92ab48b0f50b41f26fbc9e895f34a4fc53 (patch) | |
tree | c1d67533ac74b5749eca3ed6fb11a8a7bd8c8382 | |
parent | 827bdfd16adf324f118f843cb4d1eea94e887480 (diff) | |
download | luarocks-4c650b92ab48b0f50b41f26fbc9e895f34a4fc53.tar.gz luarocks-4c650b92ab48b0f50b41f26fbc9e895f34a4fc53.tar.bz2 luarocks-4c650b92ab48b0f50b41f26fbc9e895f34a4fc53.zip |
fixes permission checks on Windows with VirtualStore redirection
-rw-r--r-- | src/luarocks/fs/win32.lua | 42 |
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") | |||
9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
10 | local util = require("luarocks.util") | 10 | local 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 | ||
15 | local _prefix = "type NUL && " | ||
16 | local _popen, _execute = io.popen, os.execute | ||
17 | io.popen = function(cmd, ...) return _popen(_prefix..cmd, ...) end | ||
18 | os.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) |
174 | end | 183 | end |
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. | ||
191 | function 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 | ||
217 | end | ||