1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-15 04:09:49 +00:00

fixed: issue on calculating absolute path name of a symbol link

This commit is contained in:
skywind3000
2019-02-03 00:17:37 +08:00
parent f482f32cd3
commit 1401eb39a0

19
z.lua
View File

@@ -309,13 +309,28 @@ function os.path.abspath(path)
else
local test = os.path.which('realpath')
if test ~= nil and test ~= '' then
return os.call('realpath \'' .. path .. '\'')
test = os.call('realpath -s \'' .. path .. '\' 2> /dev/null')
if test ~= nil and test ~= '' then
return test
end
end
if os.path.isdir(path) then
if os.path.exists('/bin/sh') and os.path.exists('/bin/pwd') then
local cmd = "/bin/sh -c 'cd \"" ..path .."\"; /bin/pwd'"
test = os.call(cmd)
if test ~= nil and test ~= '' then
return test
end
end
end
local test = os.path.which('perl')
if test ~= nil and test ~= '' then
local s = 'perl -MCwd -e "print Cwd::realpath(\\$ARGV[0])" \'%s\''
local s = string.format(s, path)
return os.call(s)
test = os.call(s)
if test ~= nil and test ~= '' then
return test
end
end
for _, python in pairs({'python', 'python2', 'python3'}) do
local s = 'sys.stdout.write(os.path.abspath(sys.argv[1]))'