Skip to content

Commit e5c78e3

Browse files
authored
Merge pull request #50 from contrun/master
fix spurious file not exists
2 parents 6057644 + 1fb4f25 commit e5c78e3

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

z.lua

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ function string:startswith(text)
158158
return false
159159
end
160160

161+
function string:endswith(text)
162+
return text == "" or self:sub(-#text) == text
163+
end
164+
161165
function string:lstrip()
162166
if self == nil then return nil end
163167
local s = self:gsub('^%s+', '')
@@ -418,22 +422,20 @@ end
418422
function os.path.isdir(pathname)
419423
if pathname == '/' then
420424
return true
425+
elseif pathname == '' then
426+
return false
421427
elseif windows then
422428
if pathname == '\\' then
423429
return true
424430
elseif pathname:match('^%a:[/\\]$') then
425431
return true
426432
end
427433
end
428-
local name = pathname .. '/'
429-
local ok, err, code = os.rename(name, name)
430-
if not ok then
431-
if code == 13 then
432-
return true
433-
end
434-
return false
434+
local name = pathname
435+
if not name:endswith('/') then
436+
name = name .. '/'
435437
end
436-
return true
438+
return os.path.exists(name)
437439
end
438440

439441

@@ -446,6 +448,13 @@ function os.path.exists(name)
446448
if code == 13 then
447449
return true
448450
end
451+
if code == 30 then
452+
local f = io.open(name,"r")
453+
if f ~= nil then
454+
io.close(f)
455+
return true
456+
end
457+
end
449458
return false
450459
end
451460
return true

0 commit comments

Comments
 (0)