diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_cmds.c | 4 | ||||
-rw-r--r-- | src/nvim/fileio.c | 22 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 15 | ||||
-rw-r--r-- | src/nvim/undo.c | 5 |
4 files changed, 22 insertions, 24 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 180a786ed6..0a26026d7b 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1606,13 +1606,13 @@ void write_viminfo(char_u *file, int forceit) fp_out = mch_fopen((char *)tempname, WRITEBIN); } -#if defined(UNIX) && defined(HAVE_FCHOWN) +#ifdef UNIX /* * Make sure the owner can read/write it. This only works for * root. */ if (fp_out != NULL) { - fchown(fileno(fp_out), old_info.stat.st_uid, old_info.stat.st_gid); + os_fchown(fileno(fp_out), old_info.stat.st_uid, old_info.stat.st_gid); } #endif } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 7a8d28b230..e1f9454b52 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2711,16 +2711,10 @@ buf_write ( * - it's a hard link * - it's a symbolic link * - we don't have write permission in the directory - * - we can't set the owner/group of the new file */ if (file_info_old.stat.st_nlink > 1 || !os_get_file_info_link((char *)fname, &file_info) - || !os_file_info_id_equal(&file_info, &file_info_old) -# ifndef HAVE_FCHOWN - || file_info.stat.st_uid != file_info_old.stat.st_uid - || file_info.stat.st_gid != file_info_old.stat.st_gid -# endif - ) { + || !os_file_info_id_equal(&file_info, &file_info_old)) { backup_copy = TRUE; } else # endif @@ -2744,9 +2738,7 @@ buf_write ( backup_copy = TRUE; else { # ifdef UNIX -# ifdef HAVE_FCHOWN - fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); -# endif + os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); if (!os_get_file_info((char *)IObuff, &file_info) || file_info.stat.st_uid != file_info_old.stat.st_uid || file_info.stat.st_gid != file_info_old.stat.st_gid @@ -2909,10 +2901,7 @@ buf_write ( * others. */ if (file_info_new.stat.st_gid != file_info_old.stat.st_gid -# ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */ - && fchown(bfd, (uid_t)-1, file_info_old.stat.st_gid) != 0 -# endif - ) { + && os_fchown(bfd, -1, file_info_old.stat.st_gid) != 0) { os_setperm(backup, (perm & 0707) | ((perm & 07) << 3)); } # ifdef HAVE_SELINUX @@ -3424,19 +3413,16 @@ restore_backup: /* When creating a new file, set its owner/group to that of the original * file. Get the new device and inode number. */ if (backup != NULL && !backup_copy) { -# ifdef HAVE_FCHOWN - /* don't change the owner when it's already OK, some systems remove * permission or ACL stuff */ FileInfo file_info; if (!os_get_file_info((char *)wfname, &file_info) || file_info.stat.st_uid != file_info_old.stat.st_uid || file_info.stat.st_gid != file_info_old.stat.st_gid) { - fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); + os_fchown(fd, file_info_old.stat.st_uid, file_info_old.stat.st_gid); if (perm >= 0) /* set permission again, may have changed */ (void)os_setperm(wfname, perm); } -# endif buf_set_file_id(buf); } else if (!buf->file_id_valid) { // Set the file_id when creating a new file. diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4820a4d165..aca7005064 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -210,6 +210,21 @@ int os_setperm(const char_u *name, int perm) return FAIL; } +/// Changes the ownership of the file referred to by the open file descriptor. +/// +/// @return `0` on success, a libuv error code on failure. +/// +/// @note If the `owner` or `group` is specified as `-1`, then that ID is not +/// changed. +int os_fchown(int file_descriptor, uv_uid_t owner, uv_gid_t group) +{ + uv_fs_t request; + int result = uv_fs_fchown(uv_default_loop(), &request, file_descriptor, + owner, group, NULL); + uv_fs_req_cleanup(&request); + return result; +} + /// Check if a file exists. /// /// @return `true` if `name` exists. diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 96b83a3e2d..8c7b5b38e9 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -1119,10 +1119,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) if (os_get_file_info((char *)buf->b_ffname, &file_info_old) && os_get_file_info((char *)file_name, &file_info_new) && file_info_old.stat.st_gid != file_info_new.stat.st_gid -# ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */ - && fchown(fd, (uid_t)-1, file_info_old.stat.st_gid) != 0 -# endif - ) { + && os_fchown(fd, -1, file_info_old.stat.st_gid) != 0) { os_setperm(file_name, (perm & 0707) | ((perm & 07) << 3)); } # ifdef HAVE_SELINUX |