Skip to content

Commit

Permalink
Small cleanups for copy_file sendfile fix (#544)
Browse files Browse the repository at this point in the history
* copy_file() - fix preprocessor comments in sendfile cleanup

* copy_file() - deduplicate call to fchmod

* check for fchmod failure

* clang-format/messages

Co-authored-by: Billy Robert O'Neal <bion@microsoft.com>
  • Loading branch information
hmoffatt and BillyONeal authored May 23, 2022
1 parent b757137 commit ec42d25
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/vcpkg/base/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,11 @@ namespace vcpkg

// fcopyfile copies the mode so no need to fchmod here
return true;
#else
#else // ^^^ (defined(__APPLE__) // !defined(__APPLE__) vvv

destination_fd.fchmod(source_stat.st_mode, ec);
if (ec) return false;

#if defined(__linux__)
// https://man7.org/linux/man-pages/man2/sendfile.2.html#NOTES
// sendfile() will transfer at most 0x7ffff000 (2,147,479,552)
Expand Down Expand Up @@ -2924,14 +2928,10 @@ namespace vcpkg
remaining_size -= this_send_actual;
}

if (!ec)
{
destination_fd.fchmod(source_stat.st_mode, ec);
return true;
}
if (!ec) return true;
// Else fall back to read/write
ec.clear();
#endif // ^^^ !(defined(__APPLE__) || defined(__linux__))
#endif // ^^^ defined(__linux__)

constexpr std::size_t buffer_length = 4096;
unsigned char buffer[buffer_length];
Expand All @@ -2957,7 +2957,6 @@ namespace vcpkg
}
}

destination_fd.fchmod(source_stat.st_mode, ec);
return !ec;
#endif // ^^^ !(defined(__APPLE__)
#endif // ^^^ !_WIN32
Expand Down

0 comments on commit ec42d25

Please sign in to comment.