summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-08-28 22:29:23 +0800
committerruki <[email protected]>2018-08-28 08:56:22 +0800
commit38af3ecd45ca1c806a584a9b49eb442e3ac21dcb (patch)
treee29f14d422a967510785406537380d7962d19dd4
parent5fc12f30a2eb4193ff68b08061d3cf46a0415a5c (diff)
add path.islastsep
-rw-r--r--xmake/core/base/os.lua6
-rw-r--r--xmake/core/base/path.lua14
2 files changed, 9 insertions, 11 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index fd6ca4234..d699d8fa6 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -52,7 +52,7 @@ function os._cp(src, dst)
if os.isfile(src) then
-- the destination is directory? append the filename
- if os.isdir(dst) or dst:endswith(path.seperator()) then
+ if os.isdir(dst) or path.islastsep(dst) then
dst = path.join(dst, path.filename(src))
end
@@ -64,7 +64,7 @@ function os._cp(src, dst)
elseif os.isdir(src) then
-- the destination directory exists? append the filename
- if os.isdir(dst) or dst:endswith(path.seperator()) then
+ if os.isdir(dst) or path.islastsep(dst) then
dst = path.join(dst, path.filename(path.translate(src)))
end
@@ -92,7 +92,7 @@ function os._mv(src, dst)
if os.exists(src) then
-- the destination directory exists? append the filename
- if os.isdir(dst) or dst:endswith(path.seperator()) then
+ if os.isdir(dst) or path.islastsep(dst) then
dst = path.join(dst, path.filename(path.translate(src)))
end
diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua
index 61fd2acda..66f6e04b3 100644
--- a/xmake/core/base/path.lua
+++ b/xmake/core/base/path.lua
@@ -93,20 +93,18 @@ end
-- split path by the separator
function path.split(p)
-
- -- split it
return p:split("/\\")
end
-- get the path seperator
function path.seperator()
+ return xmake._HOST == "windows" and '\\' or '/'
+end
- -- windows?
- if xmake._HOST == "windows" then
- return '\\'
- else
- return '/'
- end
+-- the last character is the path seperator?
+function path.islastsep(p)
+ local sep = p:sub(#p, #p)
+ return xmake._HOST == "windows" and (sep == '\\' or sep == '/') or (sep == '/')
end
-- convert path pattern to a lua pattern