diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2014-02-08 18:25:57 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-02-08 18:25:57 -0200 |
commit | 0033902ed5bbcd310cfbd2301ba861a43e2233a8 (patch) | |
tree | c1e2371a63b4ab21fe2ec2cc7e7faf0e2f64a443 | |
parent | 343fbd52f2c165035aeb28b955e57ba4187b9ae7 (diff) | |
download | luarocks-0033902ed5bbcd310cfbd2301ba861a43e2233a8.tar.gz luarocks-0033902ed5bbcd310cfbd2301ba861a43e2233a8.tar.bz2 luarocks-0033902ed5bbcd310cfbd2301ba861a43e2233a8.zip |
Have separate fs.dir and fs.list_dir functions.
The first returns an iterator, the second one a table.
-rw-r--r-- | src/luarocks/deps.lua | 2 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 119 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 24 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 25 | ||||
-rw-r--r-- | src/luarocks/make.lua | 3 | ||||
-rw-r--r-- | src/luarocks/search.lua | 4 | ||||
-rw-r--r-- | src/luarocks/validate.lua | 2 |
7 files changed, 91 insertions, 88 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 0adb5834..c7d68d68 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -614,7 +614,7 @@ function check_external_deps(rockspec, mode) | |||
614 | for _, d in ipairs(paths) do | 614 | for _, d in ipairs(paths) do |
615 | if f:match("%*") then | 615 | if f:match("%*") then |
616 | local replaced = f:gsub("%.", "%%."):gsub("%*", ".*") | 616 | local replaced = f:gsub("%.", "%%."):gsub("%*", ".*") |
617 | for _, entry in ipairs(fs.list_dir(d)) do | 617 | for entry in fs.dir(d) do |
618 | if entry:match(replaced) then | 618 | if entry:match(replaced) then |
619 | found = true | 619 | found = true |
620 | break | 620 | break |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 94095004..6aca2b69 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -1,7 +1,8 @@ | |||
1 | 1 | ||
2 | --- Native Lua implementation of filesystem and platform abstractions, | 2 | --- Native Lua implementation of filesystem and platform abstractions, |
3 | -- using LuaFileSystem, LZLib, MD5 and LuaCurl. | 3 | -- using LuaFileSystem, LZLib, MD5 and LuaCurl. |
4 | module("luarocks.fs.lua", package.seeall) | 4 | -- module("luarocks.fs.lua") |
5 | local fs_lua = {} | ||
5 | 6 | ||
6 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
7 | 8 | ||
@@ -35,7 +36,7 @@ dir_separator = "/" | |||
35 | -- Adds single quotes and escapes. | 36 | -- Adds single quotes and escapes. |
36 | -- @param arg string: Unquoted argument. | 37 | -- @param arg string: Unquoted argument. |
37 | -- @return string: Quoted argument. | 38 | -- @return string: Quoted argument. |
38 | function Q(arg) | 39 | function fs_lua.Q(arg) |
39 | assert(type(arg) == "string") | 40 | assert(type(arg) == "string") |
40 | 41 | ||
41 | -- FIXME Unix-specific | 42 | -- FIXME Unix-specific |
@@ -48,7 +49,7 @@ end | |||
48 | -- for checking the result of subsequent operations. | 49 | -- for checking the result of subsequent operations. |
49 | -- @param file string: filename to test | 50 | -- @param file string: filename to test |
50 | -- @return boolean: true if file exists, false otherwise. | 51 | -- @return boolean: true if file exists, false otherwise. |
51 | function is_writable(file) | 52 | function fs_lua.is_writable(file) |
52 | assert(file) | 53 | assert(file) |
53 | file = dir.normalize(file) | 54 | file = dir.normalize(file) |
54 | local result | 55 | local result |
@@ -70,7 +71,7 @@ end | |||
70 | -- @param name string: name pattern to use for avoiding conflicts | 71 | -- @param name string: name pattern to use for avoiding conflicts |
71 | -- when creating temporary directory. | 72 | -- when creating temporary directory. |
72 | -- @return string or (nil, string): name of temporary directory or (nil, error message) on failure. | 73 | -- @return string or (nil, string): name of temporary directory or (nil, error message) on failure. |
73 | function make_temp_dir(name) | 74 | function fs_lua.make_temp_dir(name) |
74 | assert(type(name) == "string") | 75 | assert(type(name) == "string") |
75 | name = dir.normalize(name) | 76 | name = dir.normalize(name) |
76 | 77 | ||
@@ -99,7 +100,7 @@ end | |||
99 | -- @param ... Strings containing additional arguments, which are quoted. | 100 | -- @param ... Strings containing additional arguments, which are quoted. |
100 | -- @return boolean: true if command succeeds (status code 0), false | 101 | -- @return boolean: true if command succeeds (status code 0), false |
101 | -- otherwise. | 102 | -- otherwise. |
102 | function execute(command, ...) | 103 | function fs_lua.execute(command, ...) |
103 | assert(type(command) == "string") | 104 | assert(type(command) == "string") |
104 | return fs.execute_string(quote_args(command, ...)) | 105 | return fs.execute_string(quote_args(command, ...)) |
105 | end | 106 | end |
@@ -112,7 +113,7 @@ end | |||
112 | -- @param ... Strings containing additional arguments, which will be quoted. | 113 | -- @param ... Strings containing additional arguments, which will be quoted. |
113 | -- @return boolean: true if command succeeds (status code 0), false | 114 | -- @return boolean: true if command succeeds (status code 0), false |
114 | -- otherwise. | 115 | -- otherwise. |
115 | function execute_quiet(command, ...) | 116 | function fs_lua.execute_quiet(command, ...) |
116 | assert(type(command) == "string") | 117 | assert(type(command) == "string") |
117 | if cfg.verbose then -- omit silencing output | 118 | if cfg.verbose then -- omit silencing output |
118 | return fs.execute_string(quote_args(command, ...)) | 119 | return fs.execute_string(quote_args(command, ...)) |
@@ -126,7 +127,7 @@ end | |||
126 | -- @param md5sum string: The string with the expected MD5 checksum. | 127 | -- @param md5sum string: The string with the expected MD5 checksum. |
127 | -- @return boolean: true if the MD5 checksum for 'file' equals 'md5sum', false + msg if not | 128 | -- @return boolean: true if the MD5 checksum for 'file' equals 'md5sum', false + msg if not |
128 | -- or if it could not perform the check for any reason. | 129 | -- or if it could not perform the check for any reason. |
129 | function check_md5(file, md5sum) | 130 | function fs_lua.check_md5(file, md5sum) |
130 | file = dir.normalize(file) | 131 | file = dir.normalize(file) |
131 | local computed, msg = fs.get_md5(file) | 132 | local computed, msg = fs.get_md5(file) |
132 | if not computed then | 133 | if not computed then |
@@ -139,6 +140,35 @@ function check_md5(file, md5sum) | |||
139 | end | 140 | end |
140 | end | 141 | end |
141 | 142 | ||
143 | --- List the contents of a directory. | ||
144 | -- @param at string or nil: directory to list (will be the current | ||
145 | -- directory if none is given). | ||
146 | -- @return table: an array of strings with the filenames representing | ||
147 | -- the contents of a directory. | ||
148 | function fs_lua.list_dir(at) | ||
149 | local result = {} | ||
150 | for file in fs.dir(at) do | ||
151 | result[#result+1] = file | ||
152 | end | ||
153 | return result | ||
154 | end | ||
155 | |||
156 | --- Iterate over the contents of a directory. | ||
157 | -- @param at string or nil: directory to list (will be the current | ||
158 | -- directory if none is given). | ||
159 | -- @return function: an iterator function suitable for use with | ||
160 | -- the for statement. | ||
161 | function fs_lua.dir(at) | ||
162 | if not at then | ||
163 | at = fs.current_dir() | ||
164 | end | ||
165 | at = dir.normalize(at) | ||
166 | if not fs.is_dir(at) then | ||
167 | return function() end | ||
168 | end | ||
169 | return coroutine.wrap(function() fs.dir_iterator(at) end) | ||
170 | end | ||
171 | |||
142 | --------------------------------------------------------------------- | 172 | --------------------------------------------------------------------- |
143 | -- LuaFileSystem functions | 173 | -- LuaFileSystem functions |
144 | --------------------------------------------------------------------- | 174 | --------------------------------------------------------------------- |
@@ -150,7 +180,7 @@ if lfs_ok then | |||
150 | -- @param cmd string: No quoting/escaping is applied to the command. | 180 | -- @param cmd string: No quoting/escaping is applied to the command. |
151 | -- @return boolean: true if command succeeds (status code 0), false | 181 | -- @return boolean: true if command succeeds (status code 0), false |
152 | -- otherwise. | 182 | -- otherwise. |
153 | function execute_string(cmd) | 183 | function fs_lua.execute_string(cmd) |
154 | local code = os.execute(cmd) | 184 | local code = os.execute(cmd) |
155 | return (code == 0 or code == true) | 185 | return (code == 0 or code == true) |
156 | end | 186 | end |
@@ -158,7 +188,7 @@ end | |||
158 | --- Obtain current directory. | 188 | --- Obtain current directory. |
159 | -- Uses the module's internal dir stack. | 189 | -- Uses the module's internal dir stack. |
160 | -- @return string: the absolute pathname of the current directory. | 190 | -- @return string: the absolute pathname of the current directory. |
161 | function current_dir() | 191 | function fs_lua.current_dir() |
162 | return lfs.currentdir() | 192 | return lfs.currentdir() |
163 | end | 193 | end |
164 | 194 | ||
@@ -167,7 +197,7 @@ end | |||
167 | -- semantics of chdir, as it does not handle errors the same way, | 197 | -- semantics of chdir, as it does not handle errors the same way, |
168 | -- but works well for our purposes for now. | 198 | -- but works well for our purposes for now. |
169 | -- @param d string: The directory to switch to. | 199 | -- @param d string: The directory to switch to. |
170 | function change_dir(d) | 200 | function fs_lua.change_dir(d) |
171 | table.insert(dir_stack, lfs.currentdir()) | 201 | table.insert(dir_stack, lfs.currentdir()) |
172 | d = dir.normalize(d) | 202 | d = dir.normalize(d) |
173 | return lfs.chdir(d) | 203 | return lfs.chdir(d) |
@@ -176,14 +206,14 @@ end | |||
176 | --- Change directory to root. | 206 | --- Change directory to root. |
177 | -- Allows leaving a directory (e.g. for deleting it) in | 207 | -- Allows leaving a directory (e.g. for deleting it) in |
178 | -- a crossplatform way. | 208 | -- a crossplatform way. |
179 | function change_dir_to_root() | 209 | function fs_lua.change_dir_to_root() |
180 | table.insert(dir_stack, lfs.currentdir()) | 210 | table.insert(dir_stack, lfs.currentdir()) |
181 | lfs.chdir("/") -- works on Windows too | 211 | lfs.chdir("/") -- works on Windows too |
182 | end | 212 | end |
183 | 213 | ||
184 | --- Change working directory to the previous in the dir stack. | 214 | --- Change working directory to the previous in the dir stack. |
185 | -- @return true if a pop ocurred, false if the stack was empty. | 215 | -- @return true if a pop ocurred, false if the stack was empty. |
186 | function pop_dir() | 216 | function fs_lua.pop_dir() |
187 | local d = table.remove(dir_stack) | 217 | local d = table.remove(dir_stack) |
188 | if d then | 218 | if d then |
189 | lfs.chdir(d) | 219 | lfs.chdir(d) |
@@ -198,7 +228,7 @@ end | |||
198 | -- too, they are created as well. | 228 | -- too, they are created as well. |
199 | -- @param directory string: pathname of directory to create. | 229 | -- @param directory string: pathname of directory to create. |
200 | -- @return boolean or (boolean, string): true on success or (false, error message) on failure. | 230 | -- @return boolean or (boolean, string): true on success or (false, error message) on failure. |
201 | function make_dir(directory) | 231 | function fs_lua.make_dir(directory) |
202 | assert(type(directory) == "string") | 232 | assert(type(directory) == "string") |
203 | directory = dir.normalize(directory) | 233 | directory = dir.normalize(directory) |
204 | local path = nil | 234 | local path = nil |
@@ -229,7 +259,7 @@ end | |||
229 | -- Does not return errors (for example, if directory is not empty or | 259 | -- Does not return errors (for example, if directory is not empty or |
230 | -- if already does not exist) | 260 | -- if already does not exist) |
231 | -- @param d string: pathname of directory to remove. | 261 | -- @param d string: pathname of directory to remove. |
232 | function remove_dir_if_empty(d) | 262 | function fs_lua.remove_dir_if_empty(d) |
233 | assert(d) | 263 | assert(d) |
234 | d = dir.normalize(d) | 264 | d = dir.normalize(d) |
235 | lfs.rmdir(d) | 265 | lfs.rmdir(d) |
@@ -239,7 +269,7 @@ end | |||
239 | -- Does not return errors (for example, if directory is not empty or | 269 | -- Does not return errors (for example, if directory is not empty or |
240 | -- if already does not exist) | 270 | -- if already does not exist) |
241 | -- @param d string: pathname of directory to remove. | 271 | -- @param d string: pathname of directory to remove. |
242 | function remove_dir_tree_if_empty(d) | 272 | function fs_lua.remove_dir_tree_if_empty(d) |
243 | assert(d) | 273 | assert(d) |
244 | d = dir.normalize(d) | 274 | d = dir.normalize(d) |
245 | for i=1,10 do | 275 | for i=1,10 do |
@@ -255,7 +285,7 @@ end | |||
255 | -- or nil to use the source filename permissions | 285 | -- or nil to use the source filename permissions |
256 | -- @return boolean or (boolean, string): true on success, false on failure, | 286 | -- @return boolean or (boolean, string): true on success, false on failure, |
257 | -- plus an error message. | 287 | -- plus an error message. |
258 | function copy(src, dest, perms) | 288 | function fs_lua.copy(src, dest, perms) |
259 | assert(src and dest) | 289 | assert(src and dest) |
260 | src = dir.normalize(src) | 290 | src = dir.normalize(src) |
261 | dest = dir.normalize(dest) | 291 | dest = dir.normalize(dest) |
@@ -309,7 +339,7 @@ end | |||
309 | -- @param dest string: Pathname of destination | 339 | -- @param dest string: Pathname of destination |
310 | -- @return boolean or (boolean, string): true on success, false on failure, | 340 | -- @return boolean or (boolean, string): true on success, false on failure, |
311 | -- plus an error message. | 341 | -- plus an error message. |
312 | function copy_contents(src, dest) | 342 | function fs_lua.copy_contents(src, dest) |
313 | assert(src and dest) | 343 | assert(src and dest) |
314 | src = dir.normalize(src) | 344 | src = dir.normalize(src) |
315 | dest = dir.normalize(dest) | 345 | dest = dir.normalize(dest) |
@@ -354,32 +384,21 @@ end | |||
354 | --- Delete a file or a directory and all its contents. | 384 | --- Delete a file or a directory and all its contents. |
355 | -- @param name string: Pathname of source | 385 | -- @param name string: Pathname of source |
356 | -- @return nil | 386 | -- @return nil |
357 | function delete(name) | 387 | function fs_lua.delete(name) |
358 | name = dir.normalize(name) | 388 | name = dir.normalize(name) |
359 | recursive_delete(name) | 389 | recursive_delete(name) |
360 | end | 390 | end |
361 | 391 | ||
362 | --- List the contents of a directory. | 392 | --- Internal implementation function for fs.dir. |
363 | -- @param at string or nil: directory to list (will be the current | 393 | -- Yields a filename on each iteration. |
364 | -- directory if none is given). | 394 | -- @param at string: directory to list |
365 | -- @return table: an array of strings with the filenames representing | 395 | -- @return nil |
366 | -- the contents of a directory. | 396 | function fs_lua.dir_iterator(at) |
367 | function list_dir(at) | ||
368 | assert(type(at) == "string" or not at) | ||
369 | if not at then | ||
370 | at = fs.current_dir() | ||
371 | end | ||
372 | at = dir.normalize(at) | ||
373 | if not fs.is_dir(at) then | ||
374 | return {} | ||
375 | end | ||
376 | local result = {} | ||
377 | for file in lfs.dir(at) do | 397 | for file in lfs.dir(at) do |
378 | if file ~= "." and file ~= ".." then | 398 | if file ~= "." and file ~= ".." then |
379 | table.insert(result, file) | 399 | coroutine.yield(file) |
380 | end | 400 | end |
381 | end | 401 | end |
382 | return result | ||
383 | end | 402 | end |
384 | 403 | ||
385 | --- Implementation function for recursive find. | 404 | --- Implementation function for recursive find. |
@@ -405,7 +424,7 @@ end | |||
405 | -- directory if none is given). | 424 | -- directory if none is given). |
406 | -- @return table: an array of strings with the filenames representing | 425 | -- @return table: an array of strings with the filenames representing |
407 | -- the contents of a directory. | 426 | -- the contents of a directory. |
408 | function find(at) | 427 | function fs_lua.find(at) |
409 | assert(type(at) == "string" or not at) | 428 | assert(type(at) == "string" or not at) |
410 | if not at then | 429 | if not at then |
411 | at = fs.current_dir() | 430 | at = fs.current_dir() |
@@ -422,7 +441,7 @@ end | |||
422 | --- Test for existance of a file. | 441 | --- Test for existance of a file. |
423 | -- @param file string: filename to test | 442 | -- @param file string: filename to test |
424 | -- @return boolean: true if file exists, false otherwise. | 443 | -- @return boolean: true if file exists, false otherwise. |
425 | function exists(file) | 444 | function fs_lua.exists(file) |
426 | assert(file) | 445 | assert(file) |
427 | file = dir.normalize(file) | 446 | file = dir.normalize(file) |
428 | return type(lfs.attributes(file)) == "table" | 447 | return type(lfs.attributes(file)) == "table" |
@@ -431,7 +450,7 @@ end | |||
431 | --- Test is pathname is a directory. | 450 | --- Test is pathname is a directory. |
432 | -- @param file string: pathname to test | 451 | -- @param file string: pathname to test |
433 | -- @return boolean: true if it is a directory, false otherwise. | 452 | -- @return boolean: true if it is a directory, false otherwise. |
434 | function is_dir(file) | 453 | function fs_lua.is_dir(file) |
435 | assert(file) | 454 | assert(file) |
436 | file = dir.normalize(file) | 455 | file = dir.normalize(file) |
437 | return lfs.attributes(file, "mode") == "directory" | 456 | return lfs.attributes(file, "mode") == "directory" |
@@ -440,13 +459,13 @@ end | |||
440 | --- Test is pathname is a regular file. | 459 | --- Test is pathname is a regular file. |
441 | -- @param file string: pathname to test | 460 | -- @param file string: pathname to test |
442 | -- @return boolean: true if it is a file, false otherwise. | 461 | -- @return boolean: true if it is a file, false otherwise. |
443 | function is_file(file) | 462 | function fs_lua.is_file(file) |
444 | assert(file) | 463 | assert(file) |
445 | file = dir.normalize(file) | 464 | file = dir.normalize(file) |
446 | return lfs.attributes(file, "mode") == "file" | 465 | return lfs.attributes(file, "mode") == "file" |
447 | end | 466 | end |
448 | 467 | ||
449 | function set_time(file, time) | 468 | function fs_lua.set_time(file, time) |
450 | file = dir.normalize(file) | 469 | file = dir.normalize(file) |
451 | return lfs.touch(file, time) | 470 | return lfs.touch(file, time) |
452 | end | 471 | end |
@@ -459,7 +478,7 @@ end | |||
459 | 478 | ||
460 | if zip_ok then | 479 | if zip_ok then |
461 | 480 | ||
462 | function zip(zipfile, ...) | 481 | function fs_lua.zip(zipfile, ...) |
463 | return lrzip.zip(zipfile, ...) | 482 | return lrzip.zip(zipfile, ...) |
464 | end | 483 | end |
465 | 484 | ||
@@ -469,7 +488,7 @@ if unzip_ok then | |||
469 | --- Uncompress files from a .zip archive. | 488 | --- Uncompress files from a .zip archive. |
470 | -- @param zipfile string: pathname of .zip archive to be extracted. | 489 | -- @param zipfile string: pathname of .zip archive to be extracted. |
471 | -- @return boolean: true on success, false on failure. | 490 | -- @return boolean: true on success, false on failure. |
472 | function unzip(zipfile) | 491 | function fs_lua.unzip(zipfile) |
473 | local zipfile, err = luazip.open(zipfile) | 492 | local zipfile, err = luazip.open(zipfile) |
474 | if not zipfile then return nil, err end | 493 | if not zipfile then return nil, err end |
475 | local files = zipfile:files() | 494 | local files = zipfile:files() |
@@ -606,7 +625,7 @@ end | |||
606 | -- filename can be given explicitly as this second argument. | 625 | -- filename can be given explicitly as this second argument. |
607 | -- @return (boolean, string): true and the filename on success, | 626 | -- @return (boolean, string): true and the filename on success, |
608 | -- false and the error message on failure. | 627 | -- false and the error message on failure. |
609 | function download(url, filename, cache) | 628 | function fs_lua.download(url, filename, cache) |
610 | assert(type(url) == "string") | 629 | assert(type(url) == "string") |
611 | assert(type(filename) == "string" or not filename) | 630 | assert(type(filename) == "string" or not filename) |
612 | 631 | ||
@@ -649,7 +668,7 @@ if md5_ok then | |||
649 | --- Get the MD5 checksum for a file. | 668 | --- Get the MD5 checksum for a file. |
650 | -- @param file string: The file to be computed. | 669 | -- @param file string: The file to be computed. |
651 | -- @return string: The MD5 checksum or nil + error | 670 | -- @return string: The MD5 checksum or nil + error |
652 | function get_md5(file) | 671 | function fs_lua.get_md5(file) |
653 | file = fs.absolute_name(file) | 672 | file = fs.absolute_name(file) |
654 | local file = io.open(file, "rb") | 673 | local file = io.open(file, "rb") |
655 | if not file then return nil, "Failed to open file for reading: "..file end | 674 | if not file then return nil, "Failed to open file for reading: "..file end |
@@ -678,7 +697,7 @@ local octal_to_rwx = { | |||
678 | ["7"] = "rwx", | 697 | ["7"] = "rwx", |
679 | } | 698 | } |
680 | 699 | ||
681 | function chmod(file, mode) | 700 | function fs_lua.chmod(file, mode) |
682 | -- LuaPosix (as of 5.1.15) does not support octal notation... | 701 | -- LuaPosix (as of 5.1.15) does not support octal notation... |
683 | if mode:sub(1,1) == "0" then | 702 | if mode:sub(1,1) == "0" then |
684 | local new_mode = {} | 703 | local new_mode = {} |
@@ -691,7 +710,7 @@ function chmod(file, mode) | |||
691 | return err == 0 | 710 | return err == 0 |
692 | end | 711 | end |
693 | 712 | ||
694 | function get_permissions(file) | 713 | function fs_lua.get_permissions(file) |
695 | return posix.stat(file, "mode") | 714 | return posix.stat(file, "mode") |
696 | end | 715 | end |
697 | 716 | ||
@@ -704,7 +723,7 @@ end | |||
704 | --- Apply a patch. | 723 | --- Apply a patch. |
705 | -- @param patchname string: The filename of the patch. | 724 | -- @param patchname string: The filename of the patch. |
706 | -- @param patchdata string or nil: The actual patch as a string. | 725 | -- @param patchdata string or nil: The actual patch as a string. |
707 | function apply_patch(patchname, patchdata) | 726 | function fs_lua.apply_patch(patchname, patchdata) |
708 | local p, all_ok = patch.read_patch(patchname, patchdata) | 727 | local p, all_ok = patch.read_patch(patchname, patchdata) |
709 | if not all_ok then | 728 | if not all_ok then |
710 | return nil, "Failed reading patch "..patchname | 729 | return nil, "Failed reading patch "..patchname |
@@ -719,7 +738,7 @@ end | |||
719 | -- @param dest string: Pathname of destination | 738 | -- @param dest string: Pathname of destination |
720 | -- @return boolean or (boolean, string): true on success, false on failure, | 739 | -- @return boolean or (boolean, string): true on success, false on failure, |
721 | -- plus an error message. | 740 | -- plus an error message. |
722 | function move(src, dest) | 741 | function fs_lua.move(src, dest) |
723 | assert(src and dest) | 742 | assert(src and dest) |
724 | if fs.exists(dest) and not fs.is_dir(dest) then | 743 | if fs.exists(dest) and not fs.is_dir(dest) then |
725 | return false, "File already exists: "..dest | 744 | return false, "File already exists: "..dest |
@@ -740,7 +759,7 @@ end | |||
740 | -- @param flags table: the flags table passed to run() drivers. | 759 | -- @param flags table: the flags table passed to run() drivers. |
741 | -- @return boolean or (boolean, string): true on success, false on failure, | 760 | -- @return boolean or (boolean, string): true on success, false on failure, |
742 | -- plus an error message. | 761 | -- plus an error message. |
743 | function check_command_permissions(flags) | 762 | function fs_lua.check_command_permissions(flags) |
744 | local root_dir = path.root_dir(cfg.rocks_dir) | 763 | local root_dir = path.root_dir(cfg.rocks_dir) |
745 | local ok = true | 764 | local ok = true |
746 | local err = "" | 765 | local err = "" |
@@ -767,3 +786,5 @@ function check_command_permissions(flags) | |||
767 | return nil, err | 786 | return nil, err |
768 | end | 787 | end |
769 | end | 788 | end |
789 | |||
790 | return fs_lua | ||
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 84ac369c..df2eee3f 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -148,26 +148,18 @@ function delete(arg) | |||
148 | fs.execute_quiet(vars.RM, "-rf", arg) | 148 | fs.execute_quiet(vars.RM, "-rf", arg) |
149 | end | 149 | end |
150 | 150 | ||
151 | --- List the contents of a directory. | 151 | --- Internal implementation function for fs.dir. |
152 | -- @param at string or nil: directory to list (will be the current | 152 | -- Yields a filename on each iteration. |
153 | -- directory if none is given). | 153 | -- @param at string: directory to list |
154 | -- @return table: an array of strings with the filenames representing | 154 | -- @return nil |
155 | -- the contents of a directory. | 155 | function dir_iterator(at) |
156 | function list_dir(at) | ||
157 | assert(type(at) == "string" or not at) | ||
158 | if not at then | ||
159 | at = fs.current_dir() | ||
160 | end | ||
161 | if not fs.is_dir(at) then | ||
162 | return {} | ||
163 | end | ||
164 | local result = {} | ||
165 | local pipe = io.popen(command_at(at, vars.LS)) | 156 | local pipe = io.popen(command_at(at, vars.LS)) |
166 | for file in pipe:lines() do | 157 | for file in pipe:lines() do |
167 | table.insert(result, file) | 158 | if file ~= "." and file ~= ".." then |
159 | coroutine.yield(file) | ||
160 | end | ||
168 | end | 161 | end |
169 | pipe:close() | 162 | pipe:close() |
170 | return result | ||
171 | end | 163 | end |
172 | 164 | ||
173 | --- Recursively scan the contents of a directory. | 165 | --- Recursively scan the contents of a directory. |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 319a6724..55781b66 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
@@ -165,27 +165,18 @@ function delete(arg) | |||
165 | fs.execute_quiet("if exist "..fs.Q(arg.."\\").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )") | 165 | fs.execute_quiet("if exist "..fs.Q(arg.."\\").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )") |
166 | end | 166 | end |
167 | 167 | ||
168 | --- List the contents of a directory. | 168 | --- Internal implementation function for fs.dir. |
169 | -- @param at string or nil: directory to list (will be the current | 169 | -- Yields a filename on each iteration. |
170 | -- directory if none is given). | 170 | -- @param at string: directory to list |
171 | -- @return table: an array of strings with the filenames representing | 171 | -- @return nil |
172 | -- the contents of a directory. | 172 | function dir_iterator(at) |
173 | function list_dir(at) | ||
174 | assert(type(at) == "string" or not at) | ||
175 | if not at then | ||
176 | at = fs.current_dir() | ||
177 | end | ||
178 | if not fs.is_dir(at) then | ||
179 | return {} | ||
180 | end | ||
181 | local result = {} | ||
182 | local pipe = io.popen(command_at(at, fs.Q(vars.LS))) | 173 | local pipe = io.popen(command_at(at, fs.Q(vars.LS))) |
183 | for file in pipe:lines() do | 174 | for file in pipe:lines() do |
184 | table.insert(result, file) | 175 | if file ~= "." and file ~= ".." then |
176 | coroutine.yield(file) | ||
177 | end | ||
185 | end | 178 | end |
186 | pipe:close() | 179 | pipe:close() |
187 | |||
188 | return result | ||
189 | end | 180 | end |
190 | 181 | ||
191 | --- Recursively scan the contents of a directory. | 182 | --- Recursively scan the contents of a directory. |
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index af7e68e6..541d6a84 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua | |||
@@ -51,8 +51,7 @@ function run(...) | |||
51 | assert(type(rockspec) == "string" or not rockspec) | 51 | assert(type(rockspec) == "string" or not rockspec) |
52 | 52 | ||
53 | if not rockspec then | 53 | if not rockspec then |
54 | local files = fs.list_dir(fs.current_dir()) | 54 | for file in fs.dir() do |
55 | for _, file in pairs(files) do | ||
56 | if file:match("rockspec$") then | 55 | if file:match("rockspec$") then |
57 | if rockspec then | 56 | if rockspec then |
58 | return nil, "Please specify which rockspec file to use." | 57 | return nil, "Please specify which rockspec file to use." |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index ad205d6a..bd636352 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -136,14 +136,14 @@ function disk_search(repo, query, results) | |||
136 | end | 136 | end |
137 | query_arch_as_table(query) | 137 | query_arch_as_table(query) |
138 | 138 | ||
139 | for _, name in pairs(fs.list_dir(repo)) do | 139 | for name in fs.dir(repo) do |
140 | local pathname = dir.path(repo, name) | 140 | local pathname = dir.path(repo, name) |
141 | local rname, rversion, rarch = path.parse_name(name) | 141 | local rname, rversion, rarch = path.parse_name(name) |
142 | 142 | ||
143 | if rname and (pathname:match(".rockspec$") or pathname:match(".rock$")) then | 143 | if rname and (pathname:match(".rockspec$") or pathname:match(".rock$")) then |
144 | store_if_match(results, repo, rname, rversion, rarch, query) | 144 | store_if_match(results, repo, rname, rversion, rarch, query) |
145 | elseif fs.is_dir(pathname) then | 145 | elseif fs.is_dir(pathname) then |
146 | for _, version in pairs(fs.list_dir(pathname)) do | 146 | for version in fs.dir(pathname) do |
147 | if version:match("-%d+$") then | 147 | if version:match("-%d+$") then |
148 | store_if_match(results, repo, name, version, "installed", query) | 148 | store_if_match(results, repo, name, version, "installed", query) |
149 | end | 149 | end |
diff --git a/src/luarocks/validate.lua b/src/luarocks/validate.lua index 1e1e69e1..15c2c6b7 100644 --- a/src/luarocks/validate.lua +++ b/src/luarocks/validate.lua | |||
@@ -85,7 +85,7 @@ local function validate(repo, flags) | |||
85 | if not fs.exists(repo) then | 85 | if not fs.exists(repo) then |
86 | return nil, repo.." is not a local repository." | 86 | return nil, repo.." is not a local repository." |
87 | end | 87 | end |
88 | for _, file in pairs(fs.list_dir(repo)) do for _=1,1 do | 88 | for file in fs.dir(repo) do for _=1,1 do |
89 | if file == "manifest" or file == "index.html" then | 89 | if file == "manifest" or file == "index.html" then |
90 | break -- continue for | 90 | break -- continue for |
91 | end | 91 | end |