fs: add os_copy function that uses uv_fs_copyfile

This commit is contained in:
Said Al Attrach 2019-03-10 18:08:45 +01:00
parent ef5037e7f6
commit 8410c72b18
No known key found for this signature in database
GPG Key ID: E528966F5C473A35
2 changed files with 17 additions and 21 deletions

View File

@ -3517,28 +3517,10 @@ restore_backup:
MSG(_(e_interr));
ui_flush();
}
if ((fd = os_open((char *)backup, O_RDONLY, 0)) >= 0) {
if ((write_info.bw_fd = os_open((char *)fname,
O_WRONLY | O_CREAT | O_TRUNC,
perm & 0777)) >= 0) {
// copy the file.
write_info.bw_buf = smallbuf;
#ifdef HAS_BW_FLAGS
write_info.bw_flags = FIO_NOCONVERT;
#endif
while ((write_info.bw_len = read_eintr(fd, smallbuf,
SMBUFSIZE)) > 0) {
if (buf_write_bytes(&write_info) == FAIL) {
break;
}
}
if (close(write_info.bw_fd) >= 0
&& write_info.bw_len == 0) {
end = 1; // success
}
}
close(fd); // ignore errors for closing read file
// copy the file.
if (os_copy((char *)backup, (char *)fname, 0) == 0) {
end = 1;
}
} else {
if (vim_rename(backup, fname) == 0) {

View File

@ -643,6 +643,20 @@ ptrdiff_t os_write(const int fd, const char *const buf, const size_t size,
return (ptrdiff_t)written_bytes;
}
/// Copies a file from path to new_path. Currently this passes
/// the arguments through to uv_fs_copyfile.
///
/// @param path Path of file to be copied
/// @param path_new Path of new file
/// @param flags Bitwise OR of flags defined in <uv.h>
/// @return libuv error code on error
int os_copy(const char *path, const char *new_path, int flags)
{
int r;
RUN_UV_FS_FUNC(r, uv_fs_copyfile, path, new_path, flags, NULL);
return r;
}
/// Flushes file modifications to disk.
///
/// @param fd the file descriptor of the file to flush to disk.