Delete Filesystem::IterateDirectory and Filesystem::OpenFile.

BUG=webrtc:7345, webrtc:6424

Review-Url: https://codereview.webrtc.org/2894583002
Cr-Commit-Position: refs/heads/master@{#18344}
This commit is contained in:
nisse 2017-05-31 02:07:21 -07:00 committed by Commit Bot
parent 8fbc765421
commit 210832696f
8 changed files with 7 additions and 103 deletions

View File

@ -96,16 +96,13 @@ class MAYBE_FileRotatingStreamTest : public ::testing::Test {
const size_t expected_length,
const std::string& file_path) {
std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length]);
std::unique_ptr<FileStream> stream(Filesystem::OpenFile(file_path, "r"));
EXPECT_TRUE(stream);
if (!stream) {
return;
}
FileStream stream;
ASSERT_TRUE(stream.Open(file_path, "r", nullptr));
EXPECT_EQ(rtc::SR_SUCCESS,
stream->ReadAll(buffer.get(), expected_length, nullptr, nullptr));
stream.ReadAll(buffer.get(), expected_length, nullptr, nullptr));
EXPECT_EQ(0, memcmp(expected_contents, buffer.get(), expected_length));
size_t file_size = 0;
EXPECT_TRUE(stream->GetSize(&file_size));
EXPECT_TRUE(stream.GetSize(&file_size));
EXPECT_EQ(file_size, expected_length);
}
@ -136,9 +133,10 @@ TEST_F(MAYBE_FileRotatingStreamTest, EmptyWrite) {
WriteAndFlush("a", 0);
std::string logfile_path = stream_->GetFilePath(0);
std::unique_ptr<FileStream> stream(Filesystem::OpenFile(logfile_path, "r"));
FileStream stream;
ASSERT_TRUE(stream.Open(logfile_path, "r", nullptr));
size_t file_size = 0;
EXPECT_TRUE(stream->GetSize(&file_size));
EXPECT_TRUE(stream.GetSize(&file_size));
EXPECT_EQ(0u, file_size);
}

View File

@ -130,8 +130,4 @@ FilesystemInterface *Filesystem::EnsureDefaultFilesystem() {
return default_filesystem_;
}
DirectoryIterator* FilesystemInterface::IterateDirectory() {
return new DirectoryIterator();
}
} // namespace rtc

View File

@ -80,17 +80,6 @@ class FilesystemInterface {
public:
virtual ~FilesystemInterface() {}
// Returns a DirectoryIterator for a given pathname.
// TODO: Do fancy abstracted stuff
virtual DirectoryIterator* IterateDirectory();
// Opens a file. Returns an open StreamInterface if function succeeds.
// Otherwise, returns null.
// TODO: Add an error param to indicate failure reason, similar to
// FileStream::Open
virtual FileStream *OpenFile(const Pathname &filename,
const std::string &mode) = 0;
// This will attempt to delete the path located at filename.
// It DCHECKs and returns false if the path points to a folder or a
// non-existent file.
@ -176,19 +165,10 @@ class Filesystem {
return cur;
}
static DirectoryIterator *IterateDirectory() {
return EnsureDefaultFilesystem()->IterateDirectory();
}
static bool CreateFolder(const Pathname &pathname) {
return EnsureDefaultFilesystem()->CreateFolder(pathname);
}
static FileStream *OpenFile(const Pathname &filename,
const std::string &mode) {
return EnsureDefaultFilesystem()->OpenFile(filename, mode);
}
static bool DeleteFile(const Pathname &filename) {
return EnsureDefaultFilesystem()->DeleteFile(filename);
}

View File

@ -30,44 +30,4 @@ TEST(MAYBE_FilesystemTest, GetTemporaryFolder) {
EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr));
}
// Test creating a temp file, reading it back in, and deleting it.
TEST(MAYBE_FilesystemTest, TestOpenFile) {
Pathname path;
EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr));
path.SetPathname(Filesystem::TempFilename(path, "ut"));
FileStream* fs;
char buf[256];
size_t bytes;
fs = Filesystem::OpenFile(path, "wb");
ASSERT_TRUE(fs != nullptr);
EXPECT_EQ(SR_SUCCESS, fs->Write("test", 4, &bytes, nullptr));
EXPECT_EQ(4U, bytes);
delete fs;
EXPECT_TRUE(Filesystem::IsFile(path));
fs = Filesystem::OpenFile(path, "rb");
ASSERT_TRUE(fs != nullptr);
EXPECT_EQ(SR_SUCCESS, fs->Read(buf, sizeof(buf), &bytes, nullptr));
EXPECT_EQ(4U, bytes);
delete fs;
EXPECT_TRUE(Filesystem::DeleteFile(path));
EXPECT_FALSE(Filesystem::IsFile(path));
}
// Test opening a non-existent file.
TEST(MAYBE_FilesystemTest, TestOpenBadFile) {
Pathname path;
EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr));
path.SetFilename("not an actual file");
EXPECT_FALSE(Filesystem::IsFile(path));
FileStream* fs = Filesystem::OpenFile(path, "rb");
EXPECT_FALSE(fs != nullptr);
}
} // namespace rtc

View File

@ -123,16 +123,6 @@ bool UnixFilesystem::CreateFolder(const Pathname &path) {
return CreateFolder(path, 0755);
}
FileStream *UnixFilesystem::OpenFile(const Pathname &filename,
const std::string &mode) {
FileStream *fs = new FileStream();
if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), nullptr)) {
delete fs;
fs = nullptr;
}
return fs;
}
bool UnixFilesystem::DeleteFile(const Pathname &filename) {
LOG(LS_INFO) << "Deleting file:" << filename.pathname();

View File

@ -34,11 +34,6 @@ class UnixFilesystem : public FilesystemInterface {
static void SetAppTempFolder(const std::string& folder);
#endif
// Opens a file. Returns an open StreamInterface if function succeeds.
// Otherwise, returns null.
FileStream* OpenFile(const Pathname& filename,
const std::string& mode) override;
// This will attempt to delete the file located at filename.
// It will fail with VERIY if you pass it a non-existant file, or a directory.
bool DeleteFile(const Pathname& filename) override;

View File

@ -63,16 +63,6 @@ bool Win32Filesystem::CreateFolder(const Pathname &pathname) {
return (::CreateDirectory(path16.c_str(), nullptr) != 0);
}
FileStream *Win32Filesystem::OpenFile(const Pathname &filename,
const std::string &mode) {
FileStream *fs = new FileStream();
if (fs && !fs->Open(filename.pathname().c_str(), mode.c_str(), nullptr)) {
delete fs;
fs = nullptr;
}
return fs;
}
bool Win32Filesystem::DeleteFile(const Pathname &filename) {
LOG(LS_INFO) << "Deleting file " << filename.pathname();
if (!IsFile(filename)) {

View File

@ -17,11 +17,6 @@ namespace rtc {
class Win32Filesystem : public FilesystemInterface {
public:
// Opens a file. Returns an open StreamInterface if function succeeds.
// Otherwise, returns null.
virtual FileStream *OpenFile(const Pathname &filename,
const std::string &mode);
// This will attempt to delete the path located at filename.
// If the path points to a folder, it will fail with VERIFY
virtual bool DeleteFile(const Pathname &filename);