diff --git a/rtc_base/file.cc b/rtc_base/file.cc index a6ee2aa99c..62024119fc 100644 --- a/rtc_base/file.cc +++ b/rtc_base/file.cc @@ -14,15 +14,6 @@ namespace rtc { -namespace { - -std::string NormalizePathname(Pathname&& path) { - path.Normalize(); - return path.pathname(); -} - -} // namespace - File::File(PlatformFile file) : file_(file) {} File::File() : file_(kInvalidPlatformFileValue) {} @@ -36,46 +27,16 @@ File File::Open(const std::string& path) { return File(OpenPlatformFile(path)); } -// static -File File::Open(Pathname&& path) { - return Open(NormalizePathname(std::move(path))); -} - -// static -File File::Open(const Pathname& path) { - return Open(Pathname(path)); -} - // static File File::Create(const std::string& path) { return File(CreatePlatformFile(path)); } -// static -File File::Create(Pathname&& path) { - return Create(NormalizePathname(std::move(path))); -} - -// static -File File::Create(const Pathname& path) { - return Create(Pathname(path)); -} - // static bool File::Remove(const std::string& path) { return RemoveFile(path); } -// static -bool File::Remove(Pathname&& path) { - return Remove(NormalizePathname(std::move(path))); -} - -// static -bool File::Remove(const Pathname& path) { - return Remove(Pathname(path)); -} - File::File(File&& other) : file_(other.file_) { other.file_ = kInvalidPlatformFileValue; } diff --git a/rtc_base/file.h b/rtc_base/file.h index f87d9ce186..75fd93d131 100644 --- a/rtc_base/file.h +++ b/rtc_base/file.h @@ -16,7 +16,6 @@ #include #include "rtc_base/constructormagic.h" -#include "rtc_base/pathutils.h" #include "rtc_base/platform_file.h" namespace rtc { @@ -40,17 +39,11 @@ class File { // Open and Create give files with both reading and writing enabled. static File Open(const std::string& path); - static File Open(Pathname&& path); - static File Open(const Pathname& path); // If the file already exists it will be overwritten. static File Create(const std::string& path); - static File Create(Pathname&& path); - static File Create(const Pathname& path); // Remove a file in the file system. static bool Remove(const std::string& path); - static bool Remove(Pathname&& path); - static bool Remove(const Pathname& path); size_t Write(const uint8_t* data, size_t length); size_t Read(uint8_t* buffer, size_t length); diff --git a/rtc_base/file_unittest.cc b/rtc_base/file_unittest.cc index a8e39dd98e..5a72e5d1a0 100644 --- a/rtc_base/file_unittest.cc +++ b/rtc_base/file_unittest.cc @@ -163,39 +163,13 @@ TEST_F(FileTest, RandomAccessReadWrite) { EXPECT_TRUE(VerifyBuffer(out, 2, 0)); } -TEST_F(FileTest, OpenFromPathname) { - { - File file = File::Open(Pathname(path_)); - ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); - } - - { - Pathname path(path_); - File file = File::Open(path); - ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); - } -} - -TEST_F(FileTest, CreateFromPathname) { - { - File file = File::Create(Pathname(path_)); - ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); - } - - { - Pathname path(path_); - File file = File::Create(path); - ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); - } -} - TEST_F(FileTest, ShouldBeAbleToRemoveFile) { { - File file = File::Open(Pathname(path_)); + File file = File::Open(path_); ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); } - ASSERT_TRUE(File::Remove(Pathname(path_))) << "Error: " << LastError(); + ASSERT_TRUE(File::Remove(path_)) << "Error: " << LastError(); } } // namespace rtc diff --git a/test/testsupport/fileutils.cc b/test/testsupport/fileutils.cc index 23508de266..7ba24c1fea 100644 --- a/test/testsupport/fileutils.cc +++ b/test/testsupport/fileutils.cc @@ -355,6 +355,11 @@ std::string ResourcePath(const std::string& name, #endif // defined (WEBRTC_IOS) } +std::string JoinFilename(const std::string& dir, const std::string& name) { + RTC_CHECK(!dir.empty()) << "Special cases not implemented."; + return dir + kPathDelimiter + name; +} + size_t GetFileSize(const std::string& filename) { FILE* f = fopen(filename.c_str(), "rb"); size_t size = 0; diff --git a/test/testsupport/fileutils.h b/test/testsupport/fileutils.h index 8bf19192e7..b1eec8bc00 100644 --- a/test/testsupport/fileutils.h +++ b/test/testsupport/fileutils.h @@ -67,8 +67,10 @@ std::string GenerateTempFilename(const std::string& dir, // If a directory path is prepended to the filename, a subdirectory // hierarchy reflecting that path is assumed to be present. // extension - File extension, without the dot, i.e. "bmp" or "yuv". -std::string ResourcePath(const std::string& name, - const std::string& extension); +std::string ResourcePath(const std::string& name, const std::string& extension); + +// Joins directory name and file name, separated by the path delimiter. +std::string JoinFilename(const std::string& dir, const std::string& name); // Gets the current working directory for the executing program. // Returns "./" if for some reason it is not possible to find the working diff --git a/test/testsupport/test_artifacts.cc b/test/testsupport/test_artifacts.cc index 3d97a94472..e9d31bbac1 100644 --- a/test/testsupport/test_artifacts.cc +++ b/test/testsupport/test_artifacts.cc @@ -15,7 +15,6 @@ #include "rtc_base/file.h" #include "rtc_base/flags.h" #include "rtc_base/logging.h" -#include "rtc_base/pathutils.h" #include "test/testsupport/fileutils.h" namespace { @@ -55,7 +54,7 @@ bool WriteToTestArtifactsDir(const char* filename, } rtc::File output = - rtc::File::Create(rtc::Pathname(FLAG_test_artifacts_dir, filename)); + rtc::File::Create(JoinFilename(FLAG_test_artifacts_dir, filename)); return output.IsOpen() && output.Write(buffer, length) == length; } diff --git a/test/testsupport/test_artifacts_unittest.cc b/test/testsupport/test_artifacts_unittest.cc index 251c5cde88..c423cd90ea 100644 --- a/test/testsupport/test_artifacts_unittest.cc +++ b/test/testsupport/test_artifacts_unittest.cc @@ -19,6 +19,7 @@ #include "rtc_base/pathutils.h" #include "rtc_base/platform_file.h" #include "test/gtest.h" +#include "test/testsupport/fileutils.h" DECLARE_string(test_artifacts_dir); @@ -42,7 +43,7 @@ TEST(IsolatedOutputTest, ShouldBeAbleToWriteContent) { const char* filename = "a-file"; const char* content = "some-contents"; if (WriteToTestArtifactsDir(filename, content)) { - rtc::Pathname out_file(FLAG_test_artifacts_dir, filename); + std::string out_file = JoinFilename(FLAG_test_artifacts_dir, filename); rtc::File input = rtc::File::Open(out_file); EXPECT_TRUE(input.IsOpen()); EXPECT_TRUE(input.Seek(0));