Delete FilesystemInterface::DeleteFolderAndContents and related methods.
Additional methods deleted: DeleteFolderContents IsTemporaryPath GetAppTempFolder Unused since cl https://codereview.webrtc.org/2872283002/ BUG=webrtc:7345,webrtc:6424 Review-Url: https://codereview.webrtc.org/2887093002 Cr-Commit-Position: refs/heads/master@{#18194}
This commit is contained in:
parent
57efb038bb
commit
b243ee91c3
@ -134,37 +134,4 @@ DirectoryIterator* FilesystemInterface::IterateDirectory() {
|
||||
return new DirectoryIterator();
|
||||
}
|
||||
|
||||
bool FilesystemInterface::DeleteFolderContents(const Pathname &folder) {
|
||||
bool success = true;
|
||||
RTC_CHECK(IsFolder(folder));
|
||||
DirectoryIterator *di = IterateDirectory();
|
||||
if (!di)
|
||||
return false;
|
||||
if (di->Iterate(folder)) {
|
||||
do {
|
||||
if (di->Name() == "." || di->Name() == "..")
|
||||
continue;
|
||||
Pathname subdir;
|
||||
subdir.SetFolder(folder.pathname());
|
||||
if (di->IsDirectory()) {
|
||||
subdir.AppendFolder(di->Name());
|
||||
if (!DeleteFolderAndContents(subdir)) {
|
||||
success = false;
|
||||
}
|
||||
} else {
|
||||
subdir.SetFilename(di->Name());
|
||||
if (!DeleteFile(subdir)) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
} while (di->Next());
|
||||
}
|
||||
delete di;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool FilesystemInterface::DeleteFolderAndContents(const Pathname& folder) {
|
||||
return DeleteFolderContents(folder) && DeleteEmptyFolder(folder);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
@ -102,15 +102,6 @@ class FilesystemInterface {
|
||||
// not be deleted.
|
||||
virtual bool DeleteEmptyFolder(const Pathname &folder) = 0;
|
||||
|
||||
// This will call IterateDirectory, to get a directory iterator, and then
|
||||
// call DeleteFolderAndContents and DeleteFile on every path contained in this
|
||||
// folder. If the folder is empty, this returns true.
|
||||
virtual bool DeleteFolderContents(const Pathname &folder);
|
||||
|
||||
// This deletes the contents of a folder, recursively, and then deletes
|
||||
// the folder itself.
|
||||
virtual bool DeleteFolderAndContents(const Pathname& folder);
|
||||
|
||||
// Creates a directory. This will call itself recursively to create /foo/bar
|
||||
// even if /foo does not exist. Returns true if the function succeeds.
|
||||
virtual bool CreateFolder(const Pathname &pathname) = 0;
|
||||
@ -130,9 +121,6 @@ class FilesystemInterface {
|
||||
// directory either exists, or is also absent.
|
||||
virtual bool IsAbsent(const Pathname& pathname) = 0;
|
||||
|
||||
// Returns true if pathname represents a temporary location on the system.
|
||||
virtual bool IsTemporaryPath(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,
|
||||
@ -148,12 +136,6 @@ class FilesystemInterface {
|
||||
virtual bool GetFileTime(const Pathname& path, FileTimeType which,
|
||||
time_t* time) = 0;
|
||||
|
||||
// Get a temporary folder that is unique to the current user and application.
|
||||
// TODO: Re-evaluate the goals of this function. We probably just need any
|
||||
// directory that won't collide with another existing directory, and which
|
||||
// will be cleaned up when the program exits.
|
||||
virtual bool GetAppTempFolder(Pathname* path) = 0;
|
||||
|
||||
// Note: These might go into some shared config section later, but they're
|
||||
// used by some methods in this interface, so we're leaving them here for now.
|
||||
void SetOrganizationName(const std::string& organization) {
|
||||
@ -211,14 +193,6 @@ class Filesystem {
|
||||
return EnsureDefaultFilesystem()->DeleteFile(filename);
|
||||
}
|
||||
|
||||
static bool DeleteFolderContents(const Pathname &folder) {
|
||||
return EnsureDefaultFilesystem()->DeleteFolderContents(folder);
|
||||
}
|
||||
|
||||
static bool DeleteFolderAndContents(const Pathname &folder) {
|
||||
return EnsureDefaultFilesystem()->DeleteFolderAndContents(folder);
|
||||
}
|
||||
|
||||
static bool MoveFile(const Pathname &old_path, const Pathname &new_path) {
|
||||
return EnsureDefaultFilesystem()->MoveFile(old_path, new_path);
|
||||
}
|
||||
@ -235,10 +209,6 @@ class Filesystem {
|
||||
return EnsureDefaultFilesystem()->IsAbsent(pathname);
|
||||
}
|
||||
|
||||
static bool IsTemporaryPath(const Pathname& pathname) {
|
||||
return EnsureDefaultFilesystem()->IsTemporaryPath(pathname);
|
||||
}
|
||||
|
||||
static bool GetTemporaryFolder(Pathname &path, bool create,
|
||||
const std::string *append) {
|
||||
return EnsureDefaultFilesystem()->GetTemporaryFolder(path, create, append);
|
||||
@ -258,10 +228,6 @@ class Filesystem {
|
||||
return EnsureDefaultFilesystem()->GetFileTime(path, which, time);
|
||||
}
|
||||
|
||||
static bool GetAppTempFolder(Pathname* path) {
|
||||
return EnsureDefaultFilesystem()->GetAppTempFolder(path);
|
||||
}
|
||||
|
||||
static void SetOrganizationName(const std::string& organization) {
|
||||
EnsureDefaultFilesystem()->SetOrganizationName(organization);
|
||||
}
|
||||
|
||||
@ -216,29 +216,6 @@ bool UnixFilesystem::IsFolder(const Pathname &path) {
|
||||
return S_ISDIR(st.st_mode);
|
||||
}
|
||||
|
||||
bool UnixFilesystem::IsTemporaryPath(const Pathname& pathname) {
|
||||
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
|
||||
RTC_DCHECK(provided_app_temp_folder_ != nullptr);
|
||||
#endif
|
||||
|
||||
const char* const kTempPrefixes[] = {
|
||||
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
|
||||
provided_app_temp_folder_,
|
||||
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
|
||||
"/private/tmp/", "/private/var/tmp/", "/private/var/folders/",
|
||||
#endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
|
||||
#else
|
||||
"/tmp/", "/var/tmp/",
|
||||
#endif // WEBRTC_ANDROID || WEBRTC_IOS
|
||||
};
|
||||
for (size_t i = 0; i < arraysize(kTempPrefixes); ++i) {
|
||||
if (0 == strncmp(pathname.pathname().c_str(), kTempPrefixes[i],
|
||||
strlen(kTempPrefixes[i])))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnixFilesystem::IsFile(const Pathname& pathname) {
|
||||
struct stat st;
|
||||
int res = ::stat(pathname.pathname().c_str(), &st);
|
||||
@ -283,36 +260,6 @@ bool UnixFilesystem::GetFileTime(const Pathname& path, FileTimeType which,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnixFilesystem::GetAppTempFolder(Pathname* path) {
|
||||
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
|
||||
RTC_DCHECK(provided_app_temp_folder_ != nullptr);
|
||||
path->SetPathname(provided_app_temp_folder_);
|
||||
return true;
|
||||
#else
|
||||
RTC_DCHECK(!application_name_.empty());
|
||||
// TODO: Consider whether we are worried about thread safety.
|
||||
if (app_temp_path_ != nullptr && strlen(app_temp_path_) > 0) {
|
||||
path->SetPathname(app_temp_path_);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create a random directory as /tmp/<appname>-<pid>-<timestamp>
|
||||
char buffer[128];
|
||||
sprintfn(buffer, arraysize(buffer), "-%d-%d",
|
||||
static_cast<int>(getpid()),
|
||||
static_cast<int>(time(0)));
|
||||
std::string folder(application_name_);
|
||||
folder.append(buffer);
|
||||
if (!GetTemporaryFolder(*path, true, &folder))
|
||||
return false;
|
||||
|
||||
delete [] app_temp_path_;
|
||||
app_temp_path_ = CopyString(path->pathname());
|
||||
// TODO: atexit(DeleteFolderAndContents(app_temp_path_));
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
char* UnixFilesystem::CopyString(const std::string& str) {
|
||||
size_t size = str.length() + 1;
|
||||
|
||||
|
||||
@ -65,9 +65,6 @@ class UnixFilesystem : public FilesystemInterface {
|
||||
// Returns true if a pathname is a directory
|
||||
bool IsFolder(const Pathname& pathname) override;
|
||||
|
||||
// Returns true if pathname represents a temporary location on the system.
|
||||
bool IsTemporaryPath(const Pathname& pathname) override;
|
||||
|
||||
// Returns true of pathname represents an existing file
|
||||
bool IsFile(const Pathname& pathname) override;
|
||||
|
||||
@ -89,9 +86,6 @@ class UnixFilesystem : public FilesystemInterface {
|
||||
FileTimeType which,
|
||||
time_t* time) override;
|
||||
|
||||
// Get a temporary folder that is unique to the current user and application.
|
||||
bool GetAppTempFolder(Pathname* path) override;
|
||||
|
||||
private:
|
||||
#if defined(WEBRTC_ANDROID) || defined(WEBRTC_MAC)
|
||||
static char* provided_app_data_folder_;
|
||||
|
||||
@ -160,17 +160,6 @@ bool Win32Filesystem::IsAbsent(const Pathname& path) {
|
||||
return (ERROR_FILE_NOT_FOUND == err || ERROR_PATH_NOT_FOUND == err);
|
||||
}
|
||||
|
||||
bool Win32Filesystem::IsTemporaryPath(const Pathname& pathname) {
|
||||
TCHAR buffer[MAX_PATH + 1];
|
||||
if (!::GetTempPath(arraysize(buffer), buffer))
|
||||
return false;
|
||||
if (!IsCurrentProcessLowIntegrity() &&
|
||||
!::GetLongPathName(buffer, buffer, arraysize(buffer)))
|
||||
return false;
|
||||
return (::strnicmp(ToUtf16(pathname.pathname()).c_str(),
|
||||
buffer, strlen(buffer)) == 0);
|
||||
}
|
||||
|
||||
bool Win32Filesystem::GetFileSize(const Pathname &pathname, size_t *size) {
|
||||
WIN32_FILE_ATTRIBUTE_DATA data = {0};
|
||||
if (::GetFileAttributesEx(ToUtf16(pathname.pathname()).c_str(),
|
||||
@ -210,11 +199,4 @@ bool Win32Filesystem::GetAppPathname(Pathname* path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Win32Filesystem::GetAppTempFolder(Pathname* path) {
|
||||
if (!GetAppPathname(path))
|
||||
return false;
|
||||
std::string filename(path->filename());
|
||||
return GetTemporaryFolder(*path, true, &filename);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
@ -51,9 +51,6 @@ class Win32Filesystem : public FilesystemInterface {
|
||||
// directory either exists, or is also absent.
|
||||
virtual bool IsAbsent(const Pathname& pathname);
|
||||
|
||||
// Returns true if pathname represents a temporary location on the system.
|
||||
virtual bool IsTemporaryPath(const Pathname& pathname);
|
||||
|
||||
// All of the following functions set pathname and return true if successful.
|
||||
// Returned paths always include a trailing backslash.
|
||||
// If create is true, the path will be recursively created.
|
||||
@ -70,9 +67,6 @@ class Win32Filesystem : public FilesystemInterface {
|
||||
virtual bool GetTemporaryFolder(Pathname &path, bool create,
|
||||
const std::string *append);
|
||||
|
||||
// Get a temporary folder that is unique to the current user and application.
|
||||
virtual bool GetAppTempFolder(Pathname* path);
|
||||
|
||||
private:
|
||||
// Returns the path to the running application.
|
||||
bool GetAppPathname(Pathname* path);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user