diff options
| author | ruki <[email protected]> | 2019-08-19 23:54:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-19 17:27:13 +0800 |
| commit | 905b289ecf007df7d30bcdcee927e46931639ea8 (patch) | |
| tree | aa0296aa54a9b349570a2d0f112c35806f3dc69e /xmake | |
| parent | 612dd5918297120bc7f0c2011fbbce90863fafaa (diff) | |
fix io.isatty
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/base/io.lua | 19 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/io.lua | 12 |
2 files changed, 6 insertions, 25 deletions
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua index aa00507f3..ac405dbac 100644 --- a/xmake/core/base/io.lua +++ b/xmake/core/base/io.lua @@ -37,7 +37,7 @@ io._stdfile = io._stdfile or io.stdfile function _file.new(filepath, fileref) local file = table.inherit(_file) file._NAME = path.filename(filepath) - file._PATH = filepath + file._PATH = path.absolute(filepath) file._FILE = fileref setmetatable(file, _file) return file @@ -149,7 +149,7 @@ function _file:isatty() return false, string.format("file(%s) has been closed!", self:name()) end local ok, errors = io.file_isatty(self._FILE) - if not ok and errors then + if ok == nil and errors then errors = string.format("file(%s): %s", self:name(), errors) end return ok, errors @@ -204,7 +204,7 @@ end function _filelock.new(lockpath, lock) local filelock = table.inherit(_filelock) filelock._NAME = path.filename(lockpath) - filelock._PATH = lockpath + filelock._PATH = path.absolute(lockpath) filelock._LOCK = lock filelock._LOCKED_NUM = 0 setmetatable(filelock, _filelock) @@ -308,8 +308,8 @@ end -- read all lines from file function io.lines(filepath, opt) + -- close on finished opt = opt or {} - if opt.close_on_finished == nil then opt.close_on_finished = true end @@ -317,7 +317,6 @@ function io.lines(filepath, opt) -- open file local file = io.open(filepath, "r", opt) if not file then - -- error return function() return nil end end @@ -366,16 +365,6 @@ function io.flush() return io.stdout:flush() end -function io.lines(filepath, opt) - opt = opt or {} - opt.close_on_finished = true - local file, errors = io.open(filepath, 'r', opt) - if file then - return file:lines() - end - return file, errors -end - -- write data to file function io.writefile(filepath, data, opt) diff --git a/xmake/core/sandbox/modules/io.lua b/xmake/core/sandbox/modules/io.lua index 7ff2d1d5e..3d6a12011 100644 --- a/xmake/core/sandbox/modules/io.lua +++ b/xmake/core/sandbox/modules/io.lua @@ -31,6 +31,7 @@ local sandbox_io_file = sandbox_io_file or {} local sandbox_io_filelock = sandbox_io_filelock or {} sandbox_io._file = sandbox_io._file or io._file sandbox_io._filelock = sandbox_io._filelock or io._filelock +sandbox_io.lines = io.lines -- get file size function sandbox_io_file.size(file) @@ -62,7 +63,7 @@ end -- this file is a tty? function sandbox_io_file.isatty(file) local ok, errors = file:_isatty() - if not ok then + if ok == nil then raise(errors) end return ok @@ -331,15 +332,6 @@ function sandbox_io.flush(file) return (file or sandbox_io.stdout):flush() end --- read lines from the given file -function sandbox_io.lines(filepath, opt) - local iter, data_or_errors = io.lines(filepath, opt) - if not iter and data_or_errors then - raise(data_or_errors) - end - return iter, data_or_errors -end - -- isatty function sandbox_io.isatty(file) file = file or sandbox_io.stdout |
