-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out implementations of functions using lfs and using shell. This way both implementations can be tested in busted in one go (and busted requires lfs). Rename fs.mtime() and fs.current_dir() to fs.get_mtime() and fs.get_current_dir().
- Loading branch information
Showing
11 changed files
with
120 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
local lfs = require "lfs" | ||
|
||
local lfs_fs = {} | ||
|
||
function lfs_fs.get_mode(path) | ||
return lfs.attributes(path, "mode") | ||
end | ||
|
||
function lfs_fs.get_current_dir() | ||
return assert(lfs.currentdir()) | ||
end | ||
|
||
function lfs_fs.get_mtime(path) | ||
return lfs.attributes(path, "modification") | ||
end | ||
|
||
function lfs_fs.dir_iter(path) | ||
return lfs.dir(path) | ||
end | ||
|
||
return lfs_fs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local utils = require "luacheck.utils" | ||
|
||
local lua_fs = {} | ||
|
||
local mode_cmd_template | ||
|
||
if utils.is_windows then | ||
mode_cmd_template = [[if exist "%s\*" (echo directory) else (if exist "%s" echo "file")]] | ||
else | ||
mode_cmd_template = [[if [ -d '%s' ]; then echo directory; elif [ -f '%s' ]; then echo file; fi]] | ||
end | ||
|
||
function lua_fs.get_mode(path) | ||
local fh = assert(io.popen(mode_cmd_template:format(path, path))) | ||
local mode = fh:read("*a"):match("^(%S*)") | ||
fh:close() | ||
return mode | ||
end | ||
|
||
local pwd_cmd = utils.is_windows and "cd" or "pwd" | ||
|
||
function lua_fs.get_current_dir() | ||
local fh = assert(io.popen(pwd_cmd)) | ||
local current_dir = fh:read("*a"):gsub("\n$", "") | ||
fh:close() | ||
return current_dir | ||
end | ||
|
||
return lua_fs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters