aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/fs/win32.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index 0280b3f0..6f7ba140 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -173,3 +173,36 @@ function replace_file(old_file, new_file)
173 return os.rename(new_file, old_file) 173 return os.rename(new_file, old_file)
174end 174end
175 175
176--- Test is file/dir is writable.
177-- Warning: testing if a file/dir is writable does not guarantee
178-- that it will remain writable and therefore it is no replacement
179-- for checking the result of subsequent operations.
180-- @param file string: filename to test
181-- @return boolean: true if file exists, false otherwise.
182function is_writable(file)
183 assert(file)
184 file = dir.normalize(file)
185 local result
186 local tmpname = 'tmpluarockstestwritable.deleteme'
187 if fs.is_dir(file) then
188 local file2 = dir.path(file, tmpname)
189 local fh = io.open(file2, 'wb')
190 result = fh ~= nil
191 if fh then fh:close() end
192 if result then
193 -- the above test might give a false positive when writing to
194 -- c:\program files\ because of VirtualStore redirection on Vista and up
195 -- So get a directory listing and check whether it's really there
196 local pipe = io.popen("dir "..fs.Q(file))
197 local dir_list = pipe:read("*a")
198 pipe:close()
199 result = (nil ~= string.find(dir_list, tmpname, 1, true))
200 end
201 os.remove(file2)
202 else
203 local fh = io.open(file, 'r+b')
204 result = fh ~= nil
205 if fh then fh:close() end
206 end
207 return result
208end