diff options
author | David L. Jones <dlj@google.com> | 2017-11-15 01:40:05 +0000 |
---|---|---|
committer | David L. Jones <dlj@google.com> | 2017-11-15 01:40:05 +0000 |
commit | d5c2cca72463233df77a065f201db31b140eb44d (patch) | |
tree | 3f9a978131033302a58b7db7db1ecf2a4622bad2 /lib/Support/FileOutputBuffer.cpp | |
parent | ce7676b8db6bac096dad4c4ad62e9e6bb8aa1064 (diff) | |
parent | dcf64df89bc6d775e266ebd6b0134d135f47a35b (diff) | |
download | llvm-testing.tar.gz |
Creating branches/google/testing and tags/google/testing/2017-11-14 from r317716testing
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/google/testing@318248 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/FileOutputBuffer.cpp')
-rw-r--r-- | lib/Support/FileOutputBuffer.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/Support/FileOutputBuffer.cpp b/lib/Support/FileOutputBuffer.cpp index 1e20b01fc4aa..8906be3aaa25 100644 --- a/lib/Support/FileOutputBuffer.cpp +++ b/lib/Support/FileOutputBuffer.cpp @@ -38,7 +38,7 @@ public: std::unique_ptr<fs::mapped_file_region> Buf) : FileOutputBuffer(Path), Buffer(std::move(Buf)), TempPath(TempPath) {} - static ErrorOr<std::unique_ptr<OnDiskBuffer>> + static Expected<std::unique_ptr<OnDiskBuffer>> create(StringRef Path, size_t Size, unsigned Mode); uint8_t *getBufferStart() const override { return (uint8_t *)Buffer->data(); } @@ -49,14 +49,14 @@ public: size_t getBufferSize() const override { return Buffer->size(); } - std::error_code commit() override { + Error commit() override { // Unmap buffer, letting OS flush dirty pages to file on disk. Buffer.reset(); // Atomically replace the existing file with the new one. auto EC = fs::rename(TempPath, FinalPath); sys::DontRemoveFileOnSignal(TempPath); - return EC; + return errorCodeToError(EC); } ~OnDiskBuffer() override { @@ -78,13 +78,13 @@ public: InMemoryBuffer(StringRef Path, MemoryBlock Buf, unsigned Mode) : FileOutputBuffer(Path), Buffer(Buf), Mode(Mode) {} - static ErrorOr<std::unique_ptr<InMemoryBuffer>> + static Expected<std::unique_ptr<InMemoryBuffer>> create(StringRef Path, size_t Size, unsigned Mode) { std::error_code EC; MemoryBlock MB = Memory::allocateMappedMemory( Size, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC); if (EC) - return EC; + return errorCodeToError(EC); return llvm::make_unique<InMemoryBuffer>(Path, MB, Mode); } @@ -96,14 +96,14 @@ public: size_t getBufferSize() const override { return Buffer.size(); } - std::error_code commit() override { + Error commit() override { int FD; std::error_code EC; if (auto EC = openFileForWrite(FinalPath, FD, fs::F_None, Mode)) - return EC; + return errorCodeToError(EC); raw_fd_ostream OS(FD, /*shouldClose=*/true, /*unbuffered=*/true); OS << StringRef((const char *)Buffer.base(), Buffer.size()); - return std::error_code(); + return Error::success(); } private: @@ -111,13 +111,13 @@ private: unsigned Mode; }; -ErrorOr<std::unique_ptr<OnDiskBuffer>> +Expected<std::unique_ptr<OnDiskBuffer>> OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) { // Create new file in same directory but with random name. SmallString<128> TempPath; int FD; if (auto EC = fs::createUniqueFile(Path + ".tmp%%%%%%%", FD, TempPath, Mode)) - return EC; + return errorCodeToError(EC); sys::RemoveFileOnSignal(TempPath); @@ -128,7 +128,7 @@ OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) { // pretty slow just like it writes specified amount of bytes, // so we should avoid calling that function. if (auto EC = fs::resize_file(FD, Size)) - return EC; + return errorCodeToError(EC); #endif // Mmap it. @@ -137,12 +137,12 @@ OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) { FD, fs::mapped_file_region::readwrite, Size, 0, EC); close(FD); if (EC) - return EC; + return errorCodeToError(EC); return llvm::make_unique<OnDiskBuffer>(Path, TempPath, std::move(MappedFile)); } // Create an instance of FileOutputBuffer. -ErrorOr<std::unique_ptr<FileOutputBuffer>> +Expected<std::unique_ptr<FileOutputBuffer>> FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) { unsigned Mode = fs::all_read | fs::all_write; if (Flags & F_executable) @@ -161,7 +161,7 @@ FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) { // destination file and write to it on commit(). switch (Stat.type()) { case fs::file_type::directory_file: - return errc::is_a_directory; + return errorCodeToError(errc::is_a_directory); case fs::file_type::regular_file: case fs::file_type::file_not_found: case fs::file_type::status_error: |