llvm.org GIT mirror llvm / 14c6360
Convert FileOutputBuffer::commit to Error. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317656 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 1 year, 9 months ago
4 changed file(s) with 11 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
5656 /// is called, the file is deleted in the destructor. The optional parameter
5757 /// is used if it turns out you want the file size to be smaller than
5858 /// initially requested.
59 virtual std::error_code commit() = 0;
59 virtual Error commit() = 0;
6060
6161 /// If this object was previously committed, the destructor just deletes
6262 /// this object. If this object was not committed, the destructor
4848
4949 size_t getBufferSize() const override { return Buffer->size(); }
5050
51 std::error_code commit() override {
51 Error commit() override {
5252 // Unmap buffer, letting OS flush dirty pages to file on disk.
5353 Buffer.reset();
5454
5555 // Atomically replace the existing file with the new one.
5656 auto EC = fs::rename(TempPath, FinalPath);
5757 sys::DontRemoveFileOnSignal(TempPath);
58 return EC;
58 return errorCodeToError(EC);
5959 }
6060
6161 ~OnDiskBuffer() override {
9595
9696 size_t getBufferSize() const override { return Buffer.size(); }
9797
98 std::error_code commit() override {
98 Error commit() override {
9999 int FD;
100100 std::error_code EC;
101101 if (auto EC = openFileForWrite(FinalPath, FD, fs::F_None, Mode))
102 return EC;
102 return errorCodeToError(EC);
103103 raw_fd_ostream OS(FD, /*shouldClose=*/true, /*unbuffered=*/true);
104104 OS << StringRef((const char *)Buffer.base(), Buffer.size());
105 return std::error_code();
105 return Error::success();
106106 }
107107
108108 private:
120120 else
121121 Buffer = std::move(*BufferOrErr);
122122 Obj.write(*Buffer);
123 if (auto EC = Buffer->commit())
124 reportError(File, EC);
123 if (auto E = Buffer->commit())
124 reportError(File, errorToErrorCode(std::move(E)));
125125 }
126126
127127 template
5050 // Write to end of buffer to verify it is writable.
5151 memcpy(Buffer->getBufferEnd() - 20, "AABBCCDDEEFFGGHHIIJJ", 20);
5252 // Commit buffer.
53 ASSERT_NO_ERROR(Buffer->commit());
53 ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
5454 }
5555
5656 // Verify file is correct size.
8888 memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20);
8989 // Write to end of buffer to verify it is writable.
9090 memcpy(Buffer->getBufferEnd() - 20, "AABBCCDDEEFFGGHHIIJJ", 20);
91 ASSERT_NO_ERROR(Buffer->commit());
91 ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
9292 }
9393
9494 // Verify file is correct size.
108108 // Start buffer with special header.
109109 memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20);
110110 // Commit buffer.
111 ASSERT_NO_ERROR(Buffer->commit());
111 ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
112112 }
113113 // Verify file exists and is executable.
114114 fs::file_status Status;