diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2018-06-27 17:40:51 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2018-06-27 18:58:29 -0700 |
| commit | 0ad79a67c76a7fbb26142b319eef069d7ba71557 (patch) | |
| tree | 0c9f29633fbd4d063f57b5599a38ab5e208b5576 /toolsrc/src | |
| parent | 898e3e3710a0221144c6ffd4472e2ef9aea8ad54 (diff) | |
| download | vcpkg-0ad79a67c76a7fbb26142b319eef069d7ba71557.tar.gz vcpkg-0ad79a67c76a7fbb26142b319eef069d7ba71557.zip | |
[vcpkg] Enable storing archives across filesystems
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/vcpkg/base/files.cpp | 44 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/build.cpp | 10 |
2 files changed, 51 insertions, 3 deletions
diff --git a/toolsrc/src/vcpkg/base/files.cpp b/toolsrc/src/vcpkg/base/files.cpp index 3d96e834b..2f937dcdc 100644 --- a/toolsrc/src/vcpkg/base/files.cpp +++ b/toolsrc/src/vcpkg/base/files.cpp @@ -4,6 +4,14 @@ #include <vcpkg/base/system.h> #include <vcpkg/base/util.h> +#if defined(__linux__) +#include <fcntl.h> +#include <sys/sendfile.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#endif + namespace vcpkg::Files { static const std::regex FILESYSTEM_INVALID_CHARACTERS_REGEX = std::regex(R"([\/:*?"<>|])"); @@ -117,6 +125,42 @@ namespace vcpkg::Files { fs::stdfs::rename(oldpath, newpath); } + virtual void rename_or_copy(const fs::path& oldpath, + const fs::path& newpath, + StringLiteral temp_suffix, + std::error_code& ec) override + { + this->rename(oldpath, newpath, ec); +#if defined(__linux__) + if (ec) + { + auto dst = newpath; + dst.replace_filename(dst.filename() + temp_suffix.c_str()); + + int i_fd = open(oldpath.c_str(), O_RDONLY); + if (i_fd == -1) return; + + int o_fd = creat(dst.c_str(), 0664); + if (o_fd == -1) + { + close(i_fd); + return; + } + + off_t bytes = 0; + struct stat info = {0}; + fstat(i_fd, &info); + auto written_bytes = sendfile(o_fd, i_fd, &bytes, info.st_size); + close(i_fd); + close(o_fd); + if (written_bytes == -1) return; + + this->rename(dst, newpath, ec); + if (ec) return; + this->remove(oldpath, ec); + } +#endif + } virtual bool remove(const fs::path& path) override { return fs::stdfs::remove(path); } virtual bool remove(const fs::path& path, std::error_code& ec) override { return fs::stdfs::remove(path, ec); } virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) override diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index bcde9217c..53d41c217 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -646,10 +646,14 @@ namespace vcpkg::Build compress_archive(paths, spec, tmp_archive_path); fs.create_directories(archive_path.parent_path(), ec); - fs.rename(tmp_archive_path, archive_path, ec); + fs.rename_or_copy(tmp_archive_path, archive_path, ".tmp", ec); if (ec) - System::println( - System::Color::warning, "Failed to store binary cache: %s", archive_path.u8string()); + { + System::println(System::Color::warning, + "Failed to store binary cache %s: %s", + archive_path.u8string(), + ec.message()); + } else System::println("Stored binary cache: %s", archive_path.u8string()); } |
