diff --git a/rtc_base/filerotatingstream.cc b/rtc_base/filerotatingstream.cc index 84227b9a07..fc87acbf10 100644 --- a/rtc_base/filerotatingstream.cc +++ b/rtc_base/filerotatingstream.cc @@ -243,12 +243,6 @@ bool FileRotatingStream::Flush() { return file_stream_->Flush(); } -bool FileRotatingStream::GetSize(size_t* size) const { - // Not possible to get accurate size on disk when writing because of - // potential buffering. - return false; -} - void FileRotatingStream::Close() { CloseCurrentFile(); } diff --git a/rtc_base/filerotatingstream.h b/rtc_base/filerotatingstream.h index 48cf727cfc..5560f3b744 100644 --- a/rtc_base/filerotatingstream.h +++ b/rtc_base/filerotatingstream.h @@ -52,8 +52,6 @@ class FileRotatingStream : public StreamInterface { size_t* written, int* error) override; bool Flush() override; - // Returns the total file size currently used on disk. - bool GetSize(size_t* size) const override; void Close() override; // Opens the appropriate file(s). Call this before using the stream. diff --git a/rtc_base/filerotatingstream_unittest.cc b/rtc_base/filerotatingstream_unittest.cc index dc23e34fc4..63ddc96975 100644 --- a/rtc_base/filerotatingstream_unittest.cc +++ b/rtc_base/filerotatingstream_unittest.cc @@ -91,18 +91,15 @@ class MAYBE_FileRotatingStreamTest : public ::testing::Test { void VerifyFileContents(const char* expected_contents, const size_t expected_length, const std::string& file_path) { - std::unique_ptr buffer(new uint8_t[expected_length]); + std::unique_ptr buffer(new uint8_t[expected_length + 1]); FileStream stream; ASSERT_TRUE(stream.Open(file_path, "r", nullptr)); size_t size_read = 0; - EXPECT_EQ(rtc::SR_SUCCESS, stream.ReadAll(buffer.get(), expected_length, - &size_read, nullptr)); + EXPECT_EQ(rtc::SR_EOS, stream.ReadAll(buffer.get(), expected_length + 1, + &size_read, nullptr)); EXPECT_EQ(size_read, expected_length); EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), std::min(expected_length, size_read))); - size_t file_size = 0; - EXPECT_TRUE(stream.GetSize(&file_size)); - EXPECT_EQ(file_size, expected_length); } std::unique_ptr stream_; @@ -134,9 +131,10 @@ TEST_F(MAYBE_FileRotatingStreamTest, EmptyWrite) { std::string logfile_path = stream_->GetFilePath(0); FileStream stream; ASSERT_TRUE(stream.Open(logfile_path, "r", nullptr)); - size_t file_size = 0; - EXPECT_TRUE(stream.GetSize(&file_size)); - EXPECT_EQ(0u, file_size); + char buf[1]; + size_t read_nbytes; + int read_error; + EXPECT_EQ(SR_EOS, stream.Read(buf, sizeof(buf), &read_nbytes, &read_error)); } // Tests that a write operation followed by a read returns the expected data diff --git a/rtc_base/logging_unittest.cc b/rtc_base/logging_unittest.cc index 079cfb1040..f804823e72 100644 --- a/rtc_base/logging_unittest.cc +++ b/rtc_base/logging_unittest.cc @@ -42,7 +42,6 @@ class StringStream : public StreamInterface { void Close() override; bool SetPosition(size_t position) override; bool GetPosition(size_t* position) const override; - bool GetSize(size_t* size) const override; bool ReserveSize(size_t size) override; private: @@ -107,12 +106,6 @@ bool StringStream::GetPosition(size_t* position) const { return true; } -bool StringStream::GetSize(size_t* size) const { - if (size) - *size = str_.size(); - return true; -} - bool StringStream::ReserveSize(size_t size) { if (read_only_) return false; diff --git a/rtc_base/memory_stream.h b/rtc_base/memory_stream.h index 4df2b6051e..0f5deb519d 100644 --- a/rtc_base/memory_stream.h +++ b/rtc_base/memory_stream.h @@ -38,7 +38,7 @@ class MemoryStream final : public StreamInterface { void Close() override; bool SetPosition(size_t position) override; bool GetPosition(size_t* position) const override; - bool GetSize(size_t* size) const override; + bool GetSize(size_t* size) const; bool ReserveSize(size_t size) override; char* GetBuffer() { return buffer_; } diff --git a/rtc_base/stream.cc b/rtc_base/stream.cc index 783625c67a..98dc1d86b6 100644 --- a/rtc_base/stream.cc +++ b/rtc_base/stream.cc @@ -9,7 +9,6 @@ */ #include #include -#include #include #include @@ -86,10 +85,6 @@ bool StreamInterface::GetPosition(size_t* position) const { return false; } -bool StreamInterface::GetSize(size_t* size) const { - return false; -} - bool StreamInterface::Flush() { return false; } @@ -146,10 +141,6 @@ bool StreamAdapterInterface::GetPosition(size_t* position) const { return stream_->GetPosition(position); } -bool StreamAdapterInterface::GetSize(size_t* size) const { - return stream_->GetSize(size); -} - bool StreamAdapterInterface::ReserveSize(size_t size) { return stream_->ReserveSize(size); } @@ -317,18 +308,6 @@ bool FileStream::GetPosition(size_t* position) const { return true; } -bool FileStream::GetSize(size_t* size) const { - RTC_DCHECK(nullptr != size); - if (!file_) - return false; - struct stat file_stats; - if (fstat(fileno(file_), &file_stats) != 0) - return false; - if (size) - *size = file_stats.st_size; - return true; -} - bool FileStream::ReserveSize(size_t size) { // TODO: extend the file to the proper length return true; diff --git a/rtc_base/stream.h b/rtc_base/stream.h index 43e7f58bc7..c74433b84d 100644 --- a/rtc_base/stream.h +++ b/rtc_base/stream.h @@ -116,10 +116,6 @@ class StreamInterface : public MessageHandler { // Returns false if the position is not known. virtual bool GetPosition(size_t* position) const; - // Get the byte length of the entire stream. Returns false if the length - // is not known. - virtual bool GetSize(size_t* size) const; - // Return true if flush is successful. virtual bool Flush(); @@ -193,7 +189,6 @@ class StreamAdapterInterface : public StreamInterface, bool SetPosition(size_t position) override; bool GetPosition(size_t* position) const override; - bool GetSize(size_t* size) const override; bool ReserveSize(size_t size) override; bool Flush() override; @@ -247,7 +242,6 @@ class FileStream : public StreamInterface { void Close() override; bool SetPosition(size_t position) override; bool GetPosition(size_t* position) const override; - bool GetSize(size_t* size) const override; bool ReserveSize(size_t size) override; bool Flush() override; diff --git a/rtc_base/stream_unittest.cc b/rtc_base/stream_unittest.cc index 0a80562820..a5a4c8efdb 100644 --- a/rtc_base/stream_unittest.cc +++ b/rtc_base/stream_unittest.cc @@ -61,8 +61,6 @@ class TestStream : public StreamInterface { return true; } - bool GetSize(size_t* size) const override { return false; } - private: size_t pos_; };