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-Commit-Position: refs/heads/master@{#19483}
This commit is contained in:
nisse 2017-08-24 02:20:46 -07:00 committed by Commit Bot
parent eaea27799d
commit a0c88878b6
10 changed files with 10 additions and 216 deletions

View File

@ -415,7 +415,6 @@ rtc_static_library("rtc_base") {
all_dependent_configs = [ ":rtc_base_all_dependent_config" ]
sources = [
"applefilesystem.mm",
"asyncinvoker-inl.h",
"asyncinvoker.cc",
"asyncinvoker.h",
@ -972,7 +971,6 @@ if (rtc_include_tests) {
sources = [
"callback_unittest.cc",
"crc32_unittest.cc",
"fileutils_unittest.cc",
"helpers_unittest.cc",
"httpbase_unittest.cc",
"httpcommon_unittest.cc",

View File

@ -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]);
}

View File

@ -102,11 +102,6 @@ class FilesystemInterface {
// 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 @@ class Filesystem {
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);

View File

@ -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

View File

@ -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 @@ TEST(LogTest, WallClockStartTime) {
#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 @@ TEST(LogTest, MAYBE_Perf) {
LogMessage::RemoveLogToStream(&stream);
stream.Close();
Filesystem::DeleteFile(path);
webrtc::test::RemoveFile(path);
LOG(LS_INFO) << "Average log time: " << TimeDiff(finish, start) << " ms";
}

View File

@ -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 @@ static int kZero = 0;
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:

View File

@ -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 @@ bool UnixFilesystem::DeleteFile(const Pathname &filename) {
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;

View File

@ -22,18 +22,6 @@ class UnixFilesystem : public FilesystemInterface {
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 @@ class UnixFilesystem : public FilesystemInterface {
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:

View File

@ -72,29 +72,6 @@ bool Win32Filesystem::DeleteFile(const Pathname &filename) {
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];

View File

@ -51,12 +51,6 @@ class Win32Filesystem : public FilesystemInterface {
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