summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-08 09:05:47 +0800
committerruki <[email protected]>2022-05-08 09:05:47 +0800
commit5683c390788dfbaa8b4259d9984689557f6aec90 (patch)
tree065c976e00c187d7764ce412e1cd91605a91ca48
parentc54cee1f42182fd046075435b01807dc63c189ac (diff)
improve os
-rw-r--r--xmake/core/sandbox/modules/os.lua16
1 files changed, 14 insertions, 2 deletions
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 3782bc42f..df47653b9 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -86,6 +86,8 @@ sandbox_os.SYSERR_NOT_FILEDIR = os.SYSERR_NOT_FILEDIR
-- copy file or directory
function sandbox_os.cp(srcpath, dstpath, opt)
assert(srcpath and dstpath)
+ srcpath = tostring(srcpath)
+ dstpath = tostring(dstpath)
local ok, errors = os.cp(vformat(srcpath), vformat(dstpath), opt)
if not ok then
os.raise(errors)
@@ -95,6 +97,8 @@ end
-- move file or directory
function sandbox_os.mv(srcpath, dstpath)
assert(srcpath and dstpath)
+ srcpath = tostring(srcpath)
+ dstpath = tostring(dstpath)
local ok, errors = os.mv(vformat(srcpath), vformat(dstpath))
if not ok then
os.raise(errors)
@@ -104,6 +108,7 @@ end
-- remove files or directories
function sandbox_os.rm(filepath)
assert(filepath)
+ filepath = tostring(filepath)
local ok, errors = os.rm(vformat(filepath))
if not ok then
os.raise(errors)
@@ -113,6 +118,8 @@ end
-- link file or directory to the new symfile
function sandbox_os.ln(srcpath, dstpath)
assert(srcpath and dstpath)
+ srcpath = tostring(srcpath)
+ dstpath = tostring(dstpath)
local ok, errors = os.ln(vformat(srcpath), vformat(dstpath))
if not ok then
os.raise(errors)
@@ -389,7 +396,7 @@ end
-- match files or directories
function sandbox_os.match(pattern, mode, callback)
- return os.match(vformat(pattern), mode, callback)
+ return os.match(vformat(tostring(pattern)), mode, callback)
end
-- match directories
@@ -410,36 +417,41 @@ end
-- is directory?
function sandbox_os.isdir(dirpath)
assert(dirpath)
+ dirpath = tostring(dirpath)
return os.isdir(vformat(dirpath))
end
-- is file?
function sandbox_os.isfile(filepath)
assert(filepath)
+ filepath = tostring(filepath)
return os.isfile(vformat(filepath))
end
-- is symlink?
function sandbox_os.islink(filepath)
assert(filepath)
+ filepath = tostring(filepath)
return os.islink(vformat(filepath))
end
-- is execute program?
function sandbox_os.isexec(filepath)
assert(filepath)
+ filepath = tostring(filepath)
return os.isexec(vformat(filepath))
end
-- exists file or directory?
function sandbox_os.exists(filedir)
assert(filedir)
+ filedir = tostring(filedir)
return os.exists(vformat(filedir))
end
-- read the content of symlink
function sandbox_os.readlink(symlink)
- local result = os.readlink(symlink)
+ local result = os.readlink(tostring(symlink))
if not result then
os.raise("cannot read link(%s)", symlink)
end