Skip to content

Commit

Permalink
Move common implementation of tools.dir_iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeterv committed May 22, 2016
1 parent 8630313 commit 69a6aff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
14 changes: 14 additions & 0 deletions src/luarocks/fs/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ function tools.execute_string(cmd)
end
end

--- Internal implementation function for fs.dir.
-- Yields a filename on each iteration.
-- @param at string: directory to list
-- @return nil
function tools.dir_iterator(at)
local pipe = io.popen(fs.command_at(at, fs.Q(vars.LS)))
for file in pipe:lines() do
if file ~= "." and file ~= ".." then
coroutine.yield(file)
end
end
pipe:close()
end

--- Download a remote file.
-- @param url string: URL to be fetched.
-- @param filename string or nil: this function attempts to detect the
Expand Down
14 changes: 0 additions & 14 deletions src/luarocks/fs/unix/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,6 @@ function tools.delete(arg)
fs.execute_quiet(vars.RM, "-rf", arg)
end

--- Internal implementation function for fs.dir.
-- Yields a filename on each iteration.
-- @param at string: directory to list
-- @return nil
function tools.dir_iterator(at)
local pipe = io.popen(fs.command_at(at, vars.LS))
for file in pipe:lines() do
if file ~= "." and file ~= ".." then
coroutine.yield(file)
end
end
pipe:close()
end

--- Recursively scan the contents of a directory.
-- @param at string or nil: directory to scan (will be the current
-- directory if none is given).
Expand Down
14 changes: 0 additions & 14 deletions src/luarocks/fs/win32/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,6 @@ function tools.delete(arg)
fs.execute_quiet("if exist "..fs.Q(arg.."\\").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )")
end

--- Internal implementation function for fs.dir.
-- Yields a filename on each iteration.
-- @param at string: directory to list
-- @return nil
function tools.dir_iterator(at)
local pipe = io.popen(fs.command_at(at, fs.Q(vars.LS)))
for file in pipe:lines() do
if file ~= "." and file ~= ".." then
coroutine.yield(file)
end
end
pipe:close()
end

--- Recursively scan the contents of a directory.
-- @param at string or nil: directory to scan (will be the current
-- directory if none is given).
Expand Down

0 comments on commit 69a6aff

Please sign in to comment.