fix absolute path handling in createDirectory

This commit is contained in:
Grump
2020-07-23 19:27:48 +02:00
parent eb00b9fd0a
commit c01aea7dfa
2 changed files with 3 additions and 1 deletions

View File

@@ -318,7 +318,7 @@ function nativefs.getDriveList()
end end
function nativefs.createDirectory(path) function nativefs.createDirectory(path)
local current = '' local current = path:sub(1, 1) == '/' and '/' or ''
for dir in path:gmatch('[^/\\]+') do for dir in path:gmatch('[^/\\]+') do
current = current .. dir .. '/' current = current .. dir .. '/'
local info = nativefs.getInfo(current, 'directory') local info = nativefs.getInfo(current, 'directory')

View File

@@ -223,6 +223,7 @@ end
function test_fs_createDirectory() function test_fs_createDirectory()
notFailed(fs.createDirectory('data/a/b/c/defg/h')) notFailed(fs.createDirectory('data/a/b/c/defg/h'))
notEquals(fs.getInfo('data/a/b/c/defg/h'), nil)
fs.remove('data/a/b/c/defg/h') fs.remove('data/a/b/c/defg/h')
fs.remove('data/a/b/c/defg') fs.remove('data/a/b/c/defg')
fs.remove('data/a/b/c') fs.remove('data/a/b/c')
@@ -231,6 +232,7 @@ function test_fs_createDirectory()
local d = fs.getWorkingDirectory() .. '/data/a' local d = fs.getWorkingDirectory() .. '/data/a'
notFailed(fs.createDirectory(d)) notFailed(fs.createDirectory(d))
notEquals(fs.getInfo(d), nil)
fs.remove(d) fs.remove(d)
end end