Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions toolsrc/src/vcpkg/base/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
#include <vcpkg/base/system.process.h>
#include <vcpkg/base/util.h>

#if defined(__linux__)
#if defined(__linux__) || defined(__APPLE__)
#include <fcntl.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#endif
#if defined(__linux__)
#include <sys/sendfile.h>
#elif defined(__APPLE__)
#include <sys/uio.h>
#include <sys/socket.h>
#endif

namespace vcpkg::Files
Expand Down Expand Up @@ -166,7 +172,7 @@ namespace vcpkg::Files
std::error_code& ec) override
{
this->rename(oldpath, newpath, ec);
#if defined(__linux__)
#if defined(__linux__) || defined(__APPLE__)
if (ec)
{
auto dst = newpath;
Expand All @@ -183,12 +189,21 @@ namespace vcpkg::Files
}

off_t bytes = 0;
#if defined(__linux__)
struct stat info = {0};
fstat(i_fd, &info);
auto written_bytes = sendfile(o_fd, i_fd, &bytes, info.st_size);
#elif defined(__APPLE__)
off_t offset = 0;
auto written_bytes = sendfile(i_fd, o_fd, offset, &bytes, NULL, 0);
#endif
close(i_fd);
close(o_fd);
if (written_bytes == -1) return;
if (written_bytes == -1)
{
System::print2(strerror(errno));
Comment thread
cbezault marked this conversation as resolved.
Outdated
return;
}

this->rename(dst, newpath, ec);
if (ec) return;
Expand Down