os/fs: Allow os_mkdir_recurse directory name to end with ///

This commit is contained in:
ZyX 2015-10-19 15:25:49 +03:00
parent 030c608b7d
commit fefcc01cc1
2 changed files with 30 additions and 2 deletions

View File

@ -366,11 +366,17 @@ int os_mkdir_recurse(const char *const dir, int32_t mode,
}
while (e != real_end) {
if (e > past_head) {
*e = '/';
*e = PATHSEP;
} else {
*past_head = past_head_save;
}
e += strlen(e);
const size_t component_len = strlen(e);
e += component_len;
if (e == real_end
&& memcnt(e - component_len, PATHSEP, component_len) == component_len) {
// Path ends with something like "////". Ignore this.
break;
}
int ret;
if ((ret = os_mkdir(curdir, mode)) != 0) {
*failed_dir = curdir;

View File

@ -564,6 +564,28 @@ describe('fs function', function()
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
it('succeeds to create a directory ending with ///', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
local ret, failed_str = os_mkdir_recurse(
'unit-test-directory/new-dir-recurse///', mode)
eq(0, ret)
eq(nil, failed_str)
eq(true, os_isdir('unit-test-directory/new-dir-recurse'))
lfs.rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
it('succeeds to create a directory ending with /', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
local ret, failed_str = os_mkdir_recurse(
'unit-test-directory/new-dir-recurse/', mode)
eq(0, ret)
eq(nil, failed_str)
eq(true, os_isdir('unit-test-directory/new-dir-recurse'))
lfs.rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
it('succeeds to create a directory tree', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
local ret, failed_str = os_mkdir_recurse(