mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
port vim_mkdir, mch_rmdir and mch_remove to libuv
This commit is contained in:
parent
136e5e5b84
commit
445f31f076
@ -24,6 +24,7 @@
|
||||
#include "tag.h"
|
||||
#include "ui.h"
|
||||
#include "window.h"
|
||||
#include "os/os.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "os_unix.h"
|
||||
#include "path.h"
|
||||
#include "ui.h"
|
||||
#include "os/os.h"
|
||||
|
||||
/*
|
||||
* Some systems have the page size in statfs.f_bsize, some in stat.st_blksize
|
||||
|
25
src/os/fs.c
25
src/os/fs.c
@ -202,3 +202,28 @@ int os_rename(const char_u *path, const char_u *new_path)
|
||||
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
int os_mkdir(const char *path, int32_t mode)
|
||||
{
|
||||
uv_fs_t request;
|
||||
int result = uv_fs_mkdir(uv_default_loop(), &request, path, mode, NULL);
|
||||
uv_fs_req_cleanup(&request);
|
||||
return result;
|
||||
}
|
||||
|
||||
int os_rmdir(const char *path)
|
||||
{
|
||||
uv_fs_t request;
|
||||
int result = uv_fs_rmdir(uv_default_loop(), &request, path, NULL);
|
||||
uv_fs_req_cleanup(&request);
|
||||
return result;
|
||||
}
|
||||
|
||||
int os_remove(const char *path)
|
||||
{
|
||||
uv_fs_t request;
|
||||
int result = uv_fs_unlink(uv_default_loop(), &request, path, NULL);
|
||||
uv_fs_req_cleanup(&request);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
15
src/os/os.h
15
src/os/os.h
@ -63,6 +63,21 @@ int os_file_is_writable(const char *name);
|
||||
/// @return `OK` for success, `FAIL` for failure.
|
||||
int os_rename(const char_u *path, const char_u *new_path);
|
||||
|
||||
/// Make a directory.
|
||||
///
|
||||
/// @return `0` for success, non-zero for failure.
|
||||
int os_mkdir(const char *path, int32_t mode);
|
||||
|
||||
/// Remove a directory.
|
||||
///
|
||||
/// @return `0` for success, non-zero for failure.
|
||||
int os_rmdir(const char *path);
|
||||
|
||||
/// Remove a file.
|
||||
///
|
||||
/// @return `0` for success, non-zero for failure.
|
||||
int os_remove(const char *path);
|
||||
|
||||
long_u os_total_mem(int special);
|
||||
const char *os_getenv(const char *name);
|
||||
int os_setenv(const char *name, const char *value, int overwrite);
|
||||
|
@ -30,14 +30,9 @@
|
||||
# include <sys/param.h> /* defines BSD, if it's a BSD system */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Sun defines FILE on SunOS 4.x.x, Solaris has a typedef for FILE
|
||||
*/
|
||||
|
||||
/* always use unlink() to remove files */
|
||||
# define vim_mkdir(x, y) mkdir((char *)(x), y)
|
||||
# define mch_rmdir(x) rmdir((char *)(x))
|
||||
# define mch_remove(x) unlink((char *)(x))
|
||||
#define vim_mkdir(x, y) os_mkdir((char *)(x), (y))
|
||||
#define mch_rmdir(x) os_rmdir((char *)(x))
|
||||
#define mch_remove(x) os_remove((char *)(x))
|
||||
|
||||
/* The number of arguments to a signal handler is configured here. */
|
||||
/* It used to be a long list of almost all systems. Any system that doesn't
|
||||
|
@ -19,6 +19,9 @@ bool os_file_exists(const char_u *name);
|
||||
bool os_file_is_readonly(char *fname);
|
||||
int os_file_is_writable(const char *name);
|
||||
int os_rename(const char_u *path, const char_u *new_path);
|
||||
int os_mkdir(const char *path, int32_t mode);
|
||||
int os_rmdir(const char *path);
|
||||
int os_remove(const char *path);
|
||||
]]
|
||||
|
||||
-- import constants parsed by ffi
|
||||
@ -94,10 +97,10 @@ describe 'fs function', ->
|
||||
eq lfs.currentdir! .. '/unit-test-directory', (ffi.string buffer)
|
||||
eq OK, result
|
||||
|
||||
describe 'os_isdir', ->
|
||||
os_isdir = (name) ->
|
||||
fs.os_isdir (to_cstr name)
|
||||
os_isdir = (name) ->
|
||||
fs.os_isdir (to_cstr name)
|
||||
|
||||
describe 'os_isdir', ->
|
||||
it 'returns false if an empty string is given', ->
|
||||
eq false, (os_isdir '')
|
||||
|
||||
@ -237,6 +240,9 @@ describe 'fs function', ->
|
||||
os_rename = (path, new_path) ->
|
||||
fs.os_rename (to_cstr path), (to_cstr new_path)
|
||||
|
||||
os_remove = (path) ->
|
||||
fs.os_remove (to_cstr path)
|
||||
|
||||
describe 'os_file_exists', ->
|
||||
it 'returns false when given a non-existing file', ->
|
||||
eq false, (os_file_exists 'non-existing-file')
|
||||
@ -270,3 +276,41 @@ describe 'fs function', ->
|
||||
file = io.open test, 'r'
|
||||
eq 'other', (file\read '*all')
|
||||
file\close!
|
||||
|
||||
describe 'os_remove', ->
|
||||
it 'returns non-zero when given a non-existing file', ->
|
||||
neq 0, (os_remove 'non-existing-file')
|
||||
|
||||
it 'removes the given file and returns 0', ->
|
||||
eq true, (os_file_exists 'unit-test-directory/test.file')
|
||||
eq 0, (os_remove 'unit-test-directory/test.file')
|
||||
eq false, (os_file_exists 'unit-test-directory/test.file')
|
||||
|
||||
describe 'folder operations', ->
|
||||
os_mkdir = (path, mode) ->
|
||||
fs.os_mkdir (to_cstr path), mode
|
||||
|
||||
os_rmdir = (path) ->
|
||||
fs.os_rmdir (to_cstr path)
|
||||
|
||||
describe 'os_mkdir', ->
|
||||
it 'returns non-zero when given a already existing directory', ->
|
||||
mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
|
||||
neq 0, (os_mkdir 'unit-test-directory', mode)
|
||||
|
||||
it 'creates a directory and returns 0', ->
|
||||
mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
|
||||
eq false, (os_isdir 'unit-test-directory/new-dir')
|
||||
eq 0, (os_mkdir 'unit-test-directory/new-dir', mode)
|
||||
eq true, (os_isdir 'unit-test-directory/new-dir')
|
||||
lfs.rmdir 'unit-test-directory/new-dir'
|
||||
|
||||
describe 'os_rmdir', ->
|
||||
it 'returns non_zero when given a non-existing directory', ->
|
||||
neq 0, (os_rmdir 'non-existing-directory')
|
||||
|
||||
it 'removes the given directory and returns 0', ->
|
||||
lfs.mkdir 'unit-test-directory/new-dir'
|
||||
eq 0, (os_rmdir 'unit-test-directory/new-dir', mode)
|
||||
eq false, (os_isdir 'unit-test-directory/new-dir')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user