diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-05-20 22:43:10 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-05-20 22:50:44 +0200 |
commit | 646c3423dd580aebb677d9a3fe0ed26f74f97e31 (patch) | |
tree | 8b6f7ce640d99c61537672d2865d1c9717f9f867 /src | |
parent | 7cc01c704c86f45854c29cb8427ed3b3029b4188 (diff) | |
download | rneovim-646c3423dd580aebb677d9a3fe0ed26f74f97e31.tar.gz rneovim-646c3423dd580aebb677d9a3fe0ed26f74f97e31.tar.bz2 rneovim-646c3423dd580aebb677d9a3fe0ed26f74f97e31.zip |
fileio: set group of backup file
Restores code removed in #9709.
uv_fs_copyfile() copies the perm bits but not the group name.
https://github.com/libuv/libuv/pull/1547
ref #9709
ref #8288
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/fileio.c | 17 | ||||
-rw-r--r-- | src/nvim/os/fs.c | 20 |
2 files changed, 33 insertions, 4 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 55463bdf30..15d7a885d5 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2868,6 +2868,23 @@ buf_write ( /* remove old backup, if present */ os_remove((char *)backup); + // set file protection same as original file, but + // strip s-bit. + (void)os_setperm((const char *)backup, perm & 0777); + +#ifdef UNIX + // + // Try to set the group of the backup same as the original file. If + // this fails, set the protection bits for the group same as the + // protection bits for others. + // + if (file_info_new.stat.st_gid != file_info_old.stat.st_gid + && os_chown((char *)backup, -1, file_info_old.stat.st_gid) != 0) { + os_setperm((const char *)backup, + (perm & 0707) | ((perm & 07) << 3)); + } +#endif + // copy the file if (os_copy((char *)fname, (char *)backup, UV_FS_COPYFILE_FICLONE) != 0) { diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 8c7dfcdee7..d1d088cf24 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -712,12 +712,24 @@ int os_setperm(const char *const name, int perm) return (r == kLibuvSuccess ? OK : FAIL); } -/// Changes the ownership of the file referred to by the open file descriptor. +/// Changes the owner and group of a file, like chown(2). /// -/// @return `0` on success, a libuv error code on failure. +/// @return 0 on success, or libuv error code on failure. +/// +/// @note If `owner` or `group` is -1, then that ID is not changed. +int os_chown(const char* path, uv_uid_t owner, uv_gid_t group) +{ + int r; + RUN_UV_FS_FUNC(r, uv_fs_chown, path, owner, group, NULL); + return r; +} + +/// Changes the owner and group of the file referred to by the open file +/// descriptor, like fchown(2). +/// +/// @return 0 on success, or libuv error code on failure. /// -/// @note If the `owner` or `group` is specified as `-1`, then that ID is not -/// changed. +/// @note If `owner` or `group` is -1, then that ID is not changed. int os_fchown(int fd, uv_uid_t owner, uv_gid_t group) { int r; |