Delete Filesystem::GetTemporaryFolder.
Testcode updated to use webrtc::test::TempFilename.
Also deletes now unused functions AppleDataDirectory,
AppleTempDirectory and AppleAppName.
BUG=webrtc:6424
Review-Url: https://codereview.webrtc.org/2995413002
Cr-Original-Commit-Position: refs/heads/master@{#19483}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: a0c88878b6bfabc4a841d0756701af2ca1b1ad76
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 477381a..a9e82e5 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -415,7 +415,6 @@
all_dependent_configs = [ ":rtc_base_all_dependent_config" ]
sources = [
- "applefilesystem.mm",
"asyncinvoker-inl.h",
"asyncinvoker.cc",
"asyncinvoker.h",
@@ -972,7 +971,6 @@
sources = [
"callback_unittest.cc",
"crc32_unittest.cc",
- "fileutils_unittest.cc",
"helpers_unittest.cc",
"httpbase_unittest.cc",
"httpcommon_unittest.cc",
diff --git a/rtc_base/applefilesystem.mm b/rtc_base/applefilesystem.mm
deleted file mode 100644
index 23df7f8..0000000
--- a/rtc_base/applefilesystem.mm
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2014 The WebRTC Project Authors. All rights reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-// This file only exists because various iOS and macOS system APIs are only
-// available from Objective-C. See unixfilesystem.cc for the only use
-// (enforced by a lack of a header file).
-
-#import <Foundation/NSPathUtilities.h>
-#import <Foundation/NSProcessInfo.h>
-#include <string.h>
-
-#include "webrtc/rtc_base/checks.h"
-#include "webrtc/rtc_base/pathutils.h"
-
-// Return a new[]'d |char*| copy of the UTF8 representation of |s|.
-// Caller owns the returned memory and must use delete[] on it.
-static char* copyString(NSString* s) {
- const char* utf8 = [s UTF8String];
- size_t len = strlen(utf8) + 1;
- char* copy = new char[len];
- // This uses a new[] + strcpy (instead of strdup) because the
- // receiver expects to be able to delete[] the returned pointer
- // (instead of free()ing it).
- strcpy(copy, utf8);
- return copy;
-}
-
-// Return a (leaked) copy of a directory name suitable for application data.
-char* AppleDataDirectory() {
- NSArray* paths = NSSearchPathForDirectoriesInDomains(
- NSApplicationSupportDirectory, NSUserDomainMask, YES);
- RTC_DCHECK([paths count] == 1);
- return copyString([paths objectAtIndex:0]);
-}
-
-// Return a (leaked) copy of a directory name suitable for use as a $TEMP.
-char* AppleTempDirectory() {
- return copyString(NSTemporaryDirectory());
-}
-
-// Return the binary's path.
-void AppleAppName(rtc::Pathname* path) {
- NSProcessInfo* pInfo = [NSProcessInfo processInfo];
- NSString* argv0 = [[pInfo arguments] objectAtIndex:0];
- path->SetPathname([argv0 UTF8String]);
-}
diff --git a/rtc_base/fileutils.h b/rtc_base/fileutils.h
index b633a38..a4a9472 100644
--- a/rtc_base/fileutils.h
+++ b/rtc_base/fileutils.h
@@ -102,11 +102,6 @@
// directory either exists, or is also absent.
virtual bool IsAbsent(const Pathname& pathname) = 0;
- // A folder appropriate for storing temporary files (Contents are
- // automatically deleted when the program exits)
- virtual bool GetTemporaryFolder(Pathname &path, bool create,
- const std::string *append) = 0;
-
virtual std::string TempFilename(const Pathname &dir,
const std::string &prefix) = 0;
@@ -156,11 +151,6 @@
return EnsureDefaultFilesystem()->IsAbsent(pathname);
}
- static bool GetTemporaryFolder(Pathname &path, bool create,
- const std::string *append) {
- return EnsureDefaultFilesystem()->GetTemporaryFolder(path, create, append);
- }
-
static std::string TempFilename(const Pathname &dir,
const std::string &prefix) {
return EnsureDefaultFilesystem()->TempFilename(dir, prefix);
diff --git a/rtc_base/fileutils_unittest.cc b/rtc_base/fileutils_unittest.cc
deleted file mode 100644
index 80dadf7..0000000
--- a/rtc_base/fileutils_unittest.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2004 The WebRTC Project Authors. All rights reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include <memory>
-
-#include "webrtc/rtc_base/fileutils.h"
-#include "webrtc/rtc_base/gunit.h"
-#include "webrtc/rtc_base/pathutils.h"
-#include "webrtc/rtc_base/stream.h"
-
-namespace rtc {
-
-#if defined (WEBRTC_ANDROID)
-// Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364.
-#define MAYBE_FilesystemTest DISABLED_FilesystemTest
-#else
-#define MAYBE_FilesystemTest FilesystemTest
-#endif
-
-// Make sure we can get a temp folder for the later tests.
-TEST(MAYBE_FilesystemTest, GetTemporaryFolder) {
- Pathname path;
- EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr));
-}
-
-} // namespace rtc
diff --git a/rtc_base/logging_unittest.cc b/rtc_base/logging_unittest.cc
index c806077..28538bb 100644
--- a/rtc_base/logging_unittest.cc
+++ b/rtc_base/logging_unittest.cc
@@ -12,9 +12,9 @@
#include "webrtc/rtc_base/gunit.h"
#include "webrtc/rtc_base/logging.h"
#include "webrtc/rtc_base/nullsocketserver.h"
-#include "webrtc/rtc_base/pathutils.h"
#include "webrtc/rtc_base/stream.h"
#include "webrtc/rtc_base/thread.h"
+#include "webrtc/test/testsupport/fileutils.h"
namespace rtc {
@@ -139,12 +139,11 @@
#endif
TEST(LogTest, MAYBE_Perf) {
- Pathname path;
- EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr));
- path.SetPathname(Filesystem::TempFilename(path, "ut"));
+ std::string path =
+ webrtc::test::TempFilename(webrtc::test::OutputPath(), "ut");
LogSinkImpl<FileStream> stream;
- EXPECT_TRUE(stream.Open(path.pathname(), "wb", nullptr));
+ EXPECT_TRUE(stream.Open(path, "wb", nullptr));
stream.DisableBuffering();
LogMessage::AddLogToStream(&stream, LS_SENSITIVE);
@@ -157,7 +156,7 @@
LogMessage::RemoveLogToStream(&stream);
stream.Close();
- Filesystem::DeleteFile(path);
+ webrtc::test::RemoveFile(path);
LOG(LS_INFO) << "Average log time: " << TimeDiff(finish, start) << " ms";
}
diff --git a/rtc_base/optionsfile_unittest.cc b/rtc_base/optionsfile_unittest.cc
index 525c317..b4f14db 100644
--- a/rtc_base/optionsfile_unittest.cc
+++ b/rtc_base/optionsfile_unittest.cc
@@ -11,10 +11,9 @@
#include <memory>
#include "webrtc/rtc_base/checks.h"
-#include "webrtc/rtc_base/fileutils.h"
#include "webrtc/rtc_base/gunit.h"
#include "webrtc/rtc_base/optionsfile.h"
-#include "webrtc/rtc_base/pathutils.h"
+#include "webrtc/test/testsupport/fileutils.h"
namespace rtc {
@@ -46,14 +45,13 @@
class MAYBE_OptionsFileTest : public testing::Test {
public:
MAYBE_OptionsFileTest() {
- Pathname dir;
- RTC_CHECK(Filesystem::GetTemporaryFolder(dir, true, nullptr));
- test_file_ = Filesystem::TempFilename(dir, ".testfile");
+ test_file_ =
+ webrtc::test::TempFilename(webrtc::test::OutputPath(), ".testfile");
OpenStore();
}
~MAYBE_OptionsFileTest() override {
- remove(test_file_.c_str());
+ webrtc::test::RemoveFile(test_file_);
}
protected:
diff --git a/rtc_base/unixfilesystem.cc b/rtc_base/unixfilesystem.cc
index 345c602..ebf20c7 100644
--- a/rtc_base/unixfilesystem.cc
+++ b/rtc_base/unixfilesystem.cc
@@ -51,42 +51,9 @@
#include "webrtc/rtc_base/stream.h"
#include "webrtc/rtc_base/stringutils.h"
-#if defined(WEBRTC_MAC)
-// Defined in applefilesystem.mm. No header file to discourage use
-// elsewhere; other places should use GetApp{Data,Temp}Folder() in
-// this file. Don't copy/paste. I mean it.
-char* AppleDataDirectory();
-char* AppleTempDirectory();
-void AppleAppName(rtc::Pathname* path);
-#endif
-
namespace rtc {
-#if !defined(WEBRTC_ANDROID) && !defined(WEBRTC_MAC)
-char* UnixFilesystem::app_temp_path_ = nullptr;
-#else
-char* UnixFilesystem::provided_app_data_folder_ = nullptr;
-char* UnixFilesystem::provided_app_temp_folder_ = nullptr;
-
-void UnixFilesystem::SetAppDataFolder(const std::string& folder) {
- delete [] provided_app_data_folder_;
- provided_app_data_folder_ = CopyString(folder);
-}
-
-void UnixFilesystem::SetAppTempFolder(const std::string& folder) {
- delete [] provided_app_temp_folder_;
- provided_app_temp_folder_ = CopyString(folder);
-}
-#endif
-
-UnixFilesystem::UnixFilesystem() {
-#if defined(WEBRTC_MAC)
- if (!provided_app_data_folder_)
- provided_app_data_folder_ = AppleDataDirectory();
- if (!provided_app_temp_folder_)
- provided_app_temp_folder_ = AppleTempDirectory();
-#endif
-}
+UnixFilesystem::UnixFilesystem() {}
UnixFilesystem::~UnixFilesystem() {}
@@ -133,31 +100,6 @@
return ::unlink(filename.pathname().c_str()) == 0;
}
-bool UnixFilesystem::GetTemporaryFolder(Pathname &pathname, bool create,
- const std::string *append) {
-#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
- RTC_DCHECK(provided_app_temp_folder_ != nullptr);
- pathname.SetPathname(provided_app_temp_folder_, "");
-#else
- if (const char* tmpdir = getenv("TMPDIR")) {
- pathname.SetPathname(tmpdir, "");
- } else if (const char* tmp = getenv("TMP")) {
- pathname.SetPathname(tmp, "");
- } else {
-#ifdef P_tmpdir
- pathname.SetPathname(P_tmpdir, "");
-#else // !P_tmpdir
- pathname.SetPathname("/tmp/", "");
-#endif // !P_tmpdir
- }
-#endif // defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS)
- if (append) {
- RTC_DCHECK(!append->empty());
- pathname.AppendFolder(*append);
- }
- return !create || CreateFolder(pathname);
-}
-
std::string UnixFilesystem::TempFilename(const Pathname &dir,
const std::string &prefix) {
int len = dir.pathname().size() + prefix.size() + 2 + 6;
diff --git a/rtc_base/unixfilesystem.h b/rtc_base/unixfilesystem.h
index 0ed36b4..7270b83 100644
--- a/rtc_base/unixfilesystem.h
+++ b/rtc_base/unixfilesystem.h
@@ -22,18 +22,6 @@
UnixFilesystem();
~UnixFilesystem() override;
-#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
- // Android does not have a native code API to fetch the app data or temp
- // folders. That needs to be passed into this class from Java. Similarly, iOS
- // only supports an Objective-C API for fetching the folder locations, so that
- // needs to be passed in here from Objective-C. Or at least that used to be
- // the case; now the ctor will do the work if necessary and possible.
- // TODO(fischman): add an Android version that uses JNI and drop the
- // SetApp*Folder() APIs once external users stop using them.
- static void SetAppDataFolder(const std::string& folder);
- static void SetAppTempFolder(const std::string& folder);
-#endif
-
// 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;
@@ -65,12 +53,6 @@
std::string TempFilename(const Pathname& dir,
const std::string& prefix) override;
- // A folder appropriate for storing temporary files (Contents are
- // automatically deleted when the program exists)
- bool GetTemporaryFolder(Pathname& path,
- bool create,
- const std::string* append) override;
-
bool GetFileSize(const Pathname& path, size_t* size) override;
private:
diff --git a/rtc_base/win32filesystem.cc b/rtc_base/win32filesystem.cc
index 973280e..4544185 100644
--- a/rtc_base/win32filesystem.cc
+++ b/rtc_base/win32filesystem.cc
@@ -72,29 +72,6 @@
return ::DeleteFile(ToUtf16(filename.pathname()).c_str()) != 0;
}
-bool Win32Filesystem::GetTemporaryFolder(Pathname &pathname, bool create,
- const std::string *append) {
- wchar_t buffer[MAX_PATH + 1];
- if (!::GetTempPath(arraysize(buffer), buffer))
- return false;
- if (!IsCurrentProcessLowIntegrity() &&
- !::GetLongPathName(buffer, buffer, arraysize(buffer)))
- return false;
- size_t len = strlen(buffer);
- if ((len > 0) && (buffer[len-1] != '\\')) {
- len += strcpyn(buffer + len, arraysize(buffer) - len, L"\\");
- }
- if (len >= arraysize(buffer) - 1)
- return false;
- pathname.clear();
- pathname.SetFolder(ToUtf8(buffer));
- if (append != nullptr) {
- RTC_DCHECK(!append->empty());
- pathname.AppendFolder(*append);
- }
- return !create || CreateFolder(pathname);
-}
-
std::string Win32Filesystem::TempFilename(const Pathname &dir,
const std::string &prefix) {
wchar_t filename[MAX_PATH];
diff --git a/rtc_base/win32filesystem.h b/rtc_base/win32filesystem.h
index f7a6ab4..9d42033 100644
--- a/rtc_base/win32filesystem.h
+++ b/rtc_base/win32filesystem.h
@@ -51,12 +51,6 @@
const std::string& prefix) override;
bool GetFileSize(const Pathname& path, size_t* size) override;
-
- // A folder appropriate for storing temporary files (Contents are
- // automatically deleted when the program exists)
- bool GetTemporaryFolder(Pathname& path,
- bool create,
- const std::string* append) override;
};
} // namespace rtc