[llvm] r351613 - Remove F_modify flag from FileOutputBuffer.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 18 16:07:57 PST 2019
Author: ruiu
Date: Fri Jan 18 16:07:57 2019
New Revision: 351613
URL: http://llvm.org/viewvc/llvm-project?rev=351613&view=rev
Log:
Remove F_modify flag from FileOutputBuffer.
This code is dead. There is no use of the feature in the entire LLVM codebase.
Differential Revision: https://reviews.llvm.org/D56939
Modified:
llvm/trunk/include/llvm/Support/FileOutputBuffer.h
llvm/trunk/lib/Support/FileOutputBuffer.cpp
llvm/trunk/unittests/Support/FileOutputBufferTest.cpp
Modified: llvm/trunk/include/llvm/Support/FileOutputBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileOutputBuffer.h?rev=351613&r1=351612&r2=351613&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileOutputBuffer.h (original)
+++ llvm/trunk/include/llvm/Support/FileOutputBuffer.h Fri Jan 18 16:07:57 2019
@@ -33,11 +33,6 @@ public:
enum {
/// set the 'x' bit on the resulting file
F_executable = 1,
-
- /// the contents of the new file are initialized from the file that exists
- /// at the location (if present). This allows in-place modification of an
- /// existing file.
- F_modify = 2
};
/// Factory method to create an OutputBuffer object which manages a read/write
Modified: llvm/trunk/lib/Support/FileOutputBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FileOutputBuffer.cpp?rev=351613&r1=351612&r2=351613&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FileOutputBuffer.cpp (original)
+++ llvm/trunk/lib/Support/FileOutputBuffer.cpp Fri Jan 18 16:07:57 2019
@@ -116,30 +116,24 @@ createInMemoryBuffer(StringRef Path, siz
}
static Expected<std::unique_ptr<OnDiskBuffer>>
-createOnDiskBuffer(StringRef Path, size_t Size, bool InitExisting,
- unsigned Mode) {
+createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) {
Expected<fs::TempFile> FileOrErr =
fs::TempFile::create(Path + ".tmp%%%%%%%", Mode);
if (!FileOrErr)
return FileOrErr.takeError();
fs::TempFile File = std::move(*FileOrErr);
- if (InitExisting) {
- if (auto EC = sys::fs::copy_file(Path, File.FD))
- return errorCodeToError(EC);
- } else {
#ifndef _WIN32
- // On Windows, CreateFileMapping (the mmap function on Windows)
- // automatically extends the underlying file. We don't need to
- // extend the file beforehand. _chsize (ftruncate on Windows) is
- // pretty slow just like it writes specified amount of bytes,
- // so we should avoid calling that function.
- if (auto EC = fs::resize_file(File.FD, Size)) {
- consumeError(File.discard());
- return errorCodeToError(EC);
- }
-#endif
+ // On Windows, CreateFileMapping (the mmap function on Windows)
+ // automatically extends the underlying file. We don't need to
+ // extend the file beforehand. _chsize (ftruncate on Windows) is
+ // pretty slow just like it writes specified amount of bytes,
+ // so we should avoid calling that function.
+ if (auto EC = fs::resize_file(File.FD, Size)) {
+ consumeError(File.discard());
+ return errorCodeToError(EC);
}
+#endif
// Mmap it.
std::error_code EC;
@@ -163,15 +157,6 @@ FileOutputBuffer::create(StringRef Path,
fs::file_status Stat;
fs::status(Path, Stat);
- if ((Flags & F_modify) && Size == size_t(-1)) {
- if (Stat.type() == fs::file_type::regular_file)
- Size = Stat.getSize();
- else if (Stat.type() == fs::file_type::file_not_found)
- return errorCodeToError(errc::no_such_file_or_directory);
- else
- return errorCodeToError(errc::invalid_argument);
- }
-
// Usually, we want to create OnDiskBuffer to create a temporary file in
// the same directory as the destination file and atomically replaces it
// by rename(2).
@@ -186,7 +171,7 @@ FileOutputBuffer::create(StringRef Path,
case fs::file_type::regular_file:
case fs::file_type::file_not_found:
case fs::file_type::status_error:
- return createOnDiskBuffer(Path, Size, !!(Flags & F_modify), Mode);
+ return createOnDiskBuffer(Path, Size, Mode);
default:
return createInMemoryBuffer(Path, Size, Mode);
}
Modified: llvm/trunk/unittests/Support/FileOutputBufferTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/FileOutputBufferTest.cpp?rev=351613&r1=351612&r2=351613&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/FileOutputBufferTest.cpp (original)
+++ llvm/trunk/unittests/Support/FileOutputBufferTest.cpp Fri Jan 18 16:07:57 2019
@@ -122,53 +122,4 @@ TEST(FileOutputBuffer, Test) {
// Clean up.
ASSERT_NO_ERROR(fs::remove(TestDirectory.str()));
}
-
-TEST(FileOutputBuffer, TestModify) {
- // Create unique temporary directory for these tests
- SmallString<128> TestDirectory;
- {
- ASSERT_NO_ERROR(
- fs::createUniqueDirectory("FileOutputBuffer-modify", TestDirectory));
- }
-
- SmallString<128> File1(TestDirectory);
- File1.append("/file");
- // First write some data.
- {
- Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
- FileOutputBuffer::create(File1, 10);
- ASSERT_NO_ERROR(errorToErrorCode(BufferOrErr.takeError()));
- std::unique_ptr<FileOutputBuffer> &Buffer = *BufferOrErr;
- memcpy(Buffer->getBufferStart(), "AAAAAAAAAA", 10);
- ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
- }
-
- // Then re-open the file for modify and change only some bytes.
- {
- Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
- FileOutputBuffer::create(File1, size_t(-1), FileOutputBuffer::F_modify);
- ASSERT_NO_ERROR(errorToErrorCode(BufferOrErr.takeError()));
- std::unique_ptr<FileOutputBuffer> &Buffer = *BufferOrErr;
- ASSERT_EQ(10U, Buffer->getBufferSize());
- uint8_t *Data = Buffer->getBufferStart();
- Data[0] = 'X';
- Data[9] = 'X';
- ASSERT_NO_ERROR(errorToErrorCode(Buffer->commit()));
- }
-
- // Finally, re-open the file for read and verify that it has the modified
- // contents.
- {
- ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = MemoryBuffer::getFile(File1);
- ASSERT_NO_ERROR(BufferOrErr.getError());
- std::unique_ptr<MemoryBuffer> Buffer = std::move(*BufferOrErr);
- ASSERT_EQ(10U, Buffer->getBufferSize());
- EXPECT_EQ(StringRef("XAAAAAAAAX"), Buffer->getBuffer());
- }
-
- // Clean up.
- ASSERT_NO_ERROR(fs::remove(File1));
- ASSERT_NO_ERROR(fs::remove(TestDirectory));
-}
-
} // anonymous namespace
More information about the llvm-commits
mailing list