mirror of
https://github.com/EngineerSmith/nativefs.git
synced 2025-11-08 23:15:02 +00:00
adjust getDirectoryItems and getInfo behavior with nonexistent files
This commit is contained in:
@@ -426,18 +426,20 @@ local function withTempMount(dir, fn)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function nativefs.getDirectoryItems(dir, callback)
|
function nativefs.getDirectoryItems(dir, callback)
|
||||||
return withTempMount(dir, function(mount)
|
local result, err = withTempMount(dir, function(mount)
|
||||||
return love.filesystem.getDirectoryItems(mount, callback)
|
return love.filesystem.getDirectoryItems(mount, callback)
|
||||||
end)
|
end)
|
||||||
|
return result or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function nativefs.getInfo(path, filtertype)
|
function nativefs.getInfo(path, filtertype)
|
||||||
local dir = path:match("(.*[\\/]).*$") or './'
|
local dir = path:match("(.*[\\/]).*$") or './'
|
||||||
local file = love.path.leaf(path)
|
local file = love.path.leaf(path)
|
||||||
return withTempMount(dir, function(mount)
|
local result, err = withTempMount(dir, function(mount)
|
||||||
local filepath = string.format('%s/%s', mount, file)
|
local filepath = string.format('%s/%s', mount, file)
|
||||||
return love.filesystem.getInfo(filepath, filtertype)
|
return love.filesystem.getInfo(filepath, filtertype)
|
||||||
end)
|
end)
|
||||||
|
return result or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return nativefs
|
return nativefs
|
||||||
|
|||||||
@@ -134,6 +134,8 @@ function test_fs_getDirectoryItems()
|
|||||||
for i = 1, #items2 do
|
for i = 1, #items2 do
|
||||||
equals(map[items2[i]], map2[items2[i]])
|
equals(map[items2[i]], map2[items2[i]])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
equals(#fs.getDirectoryItems('does_not_exist'), 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_fs_setWorkingDirectory()
|
function test_fs_setWorkingDirectory()
|
||||||
@@ -172,6 +174,8 @@ function test_fs_getInfo()
|
|||||||
notEquals(info, nil)
|
notEquals(info, nil)
|
||||||
equals(info.type, 'file')
|
equals(info.type, 'file')
|
||||||
|
|
||||||
|
equals(fs.getInfo('does_not_exist', nil))
|
||||||
|
|
||||||
local info = fs.getInfo(testFile1)
|
local info = fs.getInfo(testFile1)
|
||||||
notEquals(info, nil)
|
notEquals(info, nil)
|
||||||
equals(info.type, 'file')
|
equals(info.type, 'file')
|
||||||
|
|||||||
Reference in New Issue
Block a user