diff options
| author | ruki <[email protected]> | 2015-05-18 11:25:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-18 11:25:38 +0800 |
| commit | c94218b659016aadb3f1dc63cc82c3ae8dc14320 (patch) | |
| tree | ddbbf771f33ae55180816403473623846a79750b /xmake/scripts/base/os.lua | |
| parent | 7be8238f634969e80e678f59ab418900f846b094 (diff) | |
add some interfaces for changing directory
Diffstat (limited to 'xmake/scripts/base/os.lua')
| -rw-r--r-- | xmake/scripts/base/os.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/xmake/scripts/base/os.lua b/xmake/scripts/base/os.lua index e87eb1ec9..7da3d9dcd 100644 --- a/xmake/scripts/base/os.lua +++ b/xmake/scripts/base/os.lua @@ -98,5 +98,46 @@ function os.rm(path) return true end +-- change to directory +function os.cd(path) + + -- check + assert(path) + + -- change to the previous directory? + if path == "-" then + -- exists the previous directory? + if os._PREDIR then + path = os._PREDIR + os._PREDIR = nil + else + -- error + return false, string.format("not found the previous directory!") + end + end + + -- is directory? + if os.isdir(path) then + + -- get the current directory + local current = os.curdir() + + -- change to directory + if not os.chdir(path) then + return false, string.format("cannot change directory %s!", path) + end + + -- save the previous directory + os._PREDIR = current + + -- not exists? + else + return false, string.format("cannot change directory %s, not found this directory!", path) + end + + -- ok + return true +end + -- return module: os return os |
