Skip to content

Commit 14c6360

Browse files
committed
Convert FileOutputBuffer::commit to Error.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317656 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent aeaece7 commit 14c6360

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

include/llvm/Support/FileOutputBuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class FileOutputBuffer {
5757
/// is called, the file is deleted in the destructor. The optional parameter
5858
/// is used if it turns out you want the file size to be smaller than
5959
/// initially requested.
60-
virtual std::error_code commit() = 0;
60+
virtual Error commit() = 0;
6161

6262
/// If this object was previously committed, the destructor just deletes
6363
/// this object. If this object was not committed, the destructor

lib/Support/FileOutputBuffer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ class OnDiskBuffer : public FileOutputBuffer {
4949

5050
size_t getBufferSize() const override { return Buffer->size(); }
5151

52-
std::error_code commit() override {
52+
Error commit() override {
5353
// Unmap buffer, letting OS flush dirty pages to file on disk.
5454
Buffer.reset();
5555

5656
// Atomically replace the existing file with the new one.
5757
auto EC = fs::rename(TempPath, FinalPath);
5858
sys::DontRemoveFileOnSignal(TempPath);
59-
return EC;
59+
return errorCodeToError(EC);
6060
}
6161

6262
~OnDiskBuffer() override {
@@ -96,14 +96,14 @@ class InMemoryBuffer : public FileOutputBuffer {
9696

9797
size_t getBufferSize() const override { return Buffer.size(); }
9898

99-
std::error_code commit() override {
99+
Error commit() override {
100100
int FD;
101101
std::error_code EC;
102102
if (auto EC = openFileForWrite(FinalPath, FD, fs::F_None, Mode))
103-
return EC;
103+
return errorCodeToError(EC);
104104
raw_fd_ostream OS(FD, /*shouldClose=*/true, /*unbuffered=*/true);
105105
OS << StringRef((const char *)Buffer.base(), Buffer.size());
106-
return std::error_code();
106+
return Error::success();
107107
}
108108

109109
private:

tools/llvm-objcopy/llvm-objcopy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ void WriteObjectFile(const Object<ELFT> &Obj, StringRef File) {
121121
else
122122
Buffer = std::move(*BufferOrErr);
123123
Obj.write(*Buffer);
124-
if (auto EC = Buffer->commit())
125-
reportError(File, EC);
124+
if (auto E = Buffer->commit())
125+
reportError(File, errorToErrorCode(std::move(E)));
126126
}
127127

128128
template <class ELFT>

unittests/Support/FileOutputBufferTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ TEST(FileOutputBuffer, Test) {
5151
// Write to end of buffer to verify it is writable.
5252
memcpy(Buffer->getBufferEnd() - 20, "AABBCCDDEEFFGGHHIIJJ", 20);
5353
// Commit buffer.
54-
ASSERT_NO_ERROR(Buffer->commit());
54+
ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
5555
}
5656

5757
// Verify file is correct size.
@@ -89,7 +89,7 @@ TEST(FileOutputBuffer, Test) {
8989
memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20);
9090
// Write to end of buffer to verify it is writable.
9191
memcpy(Buffer->getBufferEnd() - 20, "AABBCCDDEEFFGGHHIIJJ", 20);
92-
ASSERT_NO_ERROR(Buffer->commit());
92+
ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
9393
}
9494

9595
// Verify file is correct size.
@@ -109,7 +109,7 @@ TEST(FileOutputBuffer, Test) {
109109
// Start buffer with special header.
110110
memcpy(Buffer->getBufferStart(), "AABBCCDDEEFFGGHHIIJJ", 20);
111111
// Commit buffer.
112-
ASSERT_NO_ERROR(Buffer->commit());
112+
ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
113113
}
114114
// Verify file exists and is executable.
115115
fs::file_status Status;

0 commit comments

Comments
 (0)