mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
Move and refactor mch_[gs]etperm to os/fs module.
This commit is contained in:
parent
1f578ec5a1
commit
c83e8b4dc7
52
src/os/fs.c
52
src/os/fs.c
@ -177,13 +177,8 @@ int mch_is_absolute_path(const char_u *fname)
|
||||
*/
|
||||
int mch_isdir(const char_u *name)
|
||||
{
|
||||
uv_fs_t request;
|
||||
int result = uv_fs_stat(uv_default_loop(), &request, (const char*) name, NULL);
|
||||
uint64_t mode = request.statbuf.st_mode;
|
||||
|
||||
uv_fs_req_cleanup(&request);
|
||||
|
||||
if (0 != result) {
|
||||
long mode = mch_getperm(name);
|
||||
if (mode < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -219,12 +214,9 @@ int mch_can_exe(const char_u *name)
|
||||
*/
|
||||
static int is_executable(const char_u *name)
|
||||
{
|
||||
uv_fs_t request;
|
||||
int result = uv_fs_stat(uv_default_loop(), &request, (const char*) name, NULL);
|
||||
uint64_t mode = request.statbuf.st_mode;
|
||||
uv_fs_req_cleanup(&request);
|
||||
long mode = mch_getperm(name);
|
||||
|
||||
if (result != 0) {
|
||||
if (mode < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -287,3 +279,39 @@ static int is_executable_in_path(const char_u *name)
|
||||
assert(false);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get file permissions for 'name'.
|
||||
* Returns -1 when it doesn't exist.
|
||||
*/
|
||||
long mch_getperm(const char_u *name)
|
||||
{
|
||||
uv_fs_t request;
|
||||
int result = uv_fs_stat(uv_default_loop(), &request, (const char*) name, NULL);
|
||||
uint64_t mode = request.statbuf.st_mode;
|
||||
uv_fs_req_cleanup(&request);
|
||||
|
||||
if (result != 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return (long) mode;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set file permission for 'name' to 'perm'.
|
||||
* Returns FAIL for failure, OK otherwise.
|
||||
*/
|
||||
int mch_setperm(const char_u *name, int perm)
|
||||
{
|
||||
uv_fs_t request;
|
||||
int result = uv_fs_chmod(uv_default_loop(), &request,
|
||||
(const char*)name, perm, NULL);
|
||||
uv_fs_req_cleanup(&request);
|
||||
|
||||
if (result != 0) {
|
||||
return FAIL;
|
||||
} else {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
@ -17,5 +17,7 @@ int mch_get_usernames(garray_T *usernames);
|
||||
int mch_get_user_name(char *s, size_t len);
|
||||
int mch_get_uname(uid_t uid, char *s, size_t len);
|
||||
char *mch_get_user_directory(const char *name);
|
||||
long mch_getperm(const char_u *name);
|
||||
int mch_setperm(const char_u *name, int perm);
|
||||
|
||||
#endif
|
||||
|
@ -1168,38 +1168,6 @@ int len; /* buffer size, only used when name gets longer */
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Get file permissions for 'name'.
|
||||
* Returns -1 when it doesn't exist.
|
||||
*/
|
||||
long mch_getperm(char_u *name)
|
||||
{
|
||||
struct stat statb;
|
||||
|
||||
/* Keep the #ifdef outside of stat(), it may be a macro. */
|
||||
if (stat((char *)name, &statb))
|
||||
return -1;
|
||||
#ifdef __INTERIX
|
||||
/* The top bit makes the value negative, which means the file doesn't
|
||||
* exist. Remove the bit, we don't use it. */
|
||||
return statb.st_mode & ~S_ADDACE;
|
||||
#else
|
||||
return statb.st_mode;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* set file permission for 'name' to 'perm'
|
||||
*
|
||||
* return FAIL for failure, OK otherwise
|
||||
*/
|
||||
int mch_setperm(char_u *name, long perm)
|
||||
{
|
||||
return chmod((char *)
|
||||
name,
|
||||
(mode_t)perm) == 0 ? OK : FAIL;
|
||||
}
|
||||
|
||||
#if defined(HAVE_ACL) || defined(PROTO)
|
||||
# ifdef HAVE_SYS_ACL_H
|
||||
# include <sys/acl.h>
|
||||
|
@ -28,8 +28,6 @@ void mch_get_host_name(char_u *s, int len);
|
||||
long mch_get_pid(void);
|
||||
void slash_adjust(char_u *p);
|
||||
void fname_case(char_u *name, int len);
|
||||
long mch_getperm(char_u *name);
|
||||
int mch_setperm(char_u *name, long perm);
|
||||
void mch_copy_sec(char_u *from_file, char_u *to_file);
|
||||
vim_acl_T mch_get_acl(char_u *fname);
|
||||
void mch_set_acl(char_u *fname, vim_acl_T aclent);
|
||||
|
Loading…
Reference in New Issue
Block a user