Revert "Delete rtc::Pathname"

This reverts commit 6b9dec0d16f2df59fa2820c5ec1341be52fb9f32.

Reason for revert: speculative revert for breaking internal projects

Original change's description:
> Delete rtc::Pathname
> 
> Bug: webrtc:6424
> Change-Id: Iec01dc5dd1426d4558983b828b67af872107d723
> Reviewed-on: https://webrtc-review.googlesource.com/c/108400
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#25479}

TBR=kwiberg@webrtc.org,nisse@webrtc.org

Change-Id: I3129a81a1d8e36b3e6c67572410bdc478ec4d5e9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:6424
Reviewed-on: https://webrtc-review.googlesource.com/c/109201
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Commit-Queue: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25490}
This commit is contained in:
Qingsi Wang
2018-11-02 16:30:10 +00:00
committed by Commit Bot
parent 273d0296a4
commit 2039ee7dce
21 changed files with 405 additions and 98 deletions

View File

@ -11,6 +11,7 @@
#include "rtc_base/fileutils.h"
#include "rtc_base/checks.h"
#include "rtc_base/pathutils.h"
#if defined(WEBRTC_WIN)
#include "rtc_base/stringutils.h" // for ToUtf16
@ -57,12 +58,12 @@ DirectoryIterator::~DirectoryIterator() {
// Starts traversing a directory.
// dir is the directory to traverse
// returns true if the directory exists and is valid
bool DirectoryIterator::Iterate(const std::string& dir) {
directory_ = dir;
bool DirectoryIterator::Iterate(const Pathname& dir) {
directory_ = dir.pathname();
#if defined(WEBRTC_WIN)
if (handle_ != INVALID_HANDLE_VALUE)
::FindClose(handle_);
std::string d = dir + '*';
std::string d = dir.pathname() + '*';
handle_ = ::FindFirstFile(ToUtf16(d).c_str(), &data_);
if (handle_ == INVALID_HANDLE_VALUE)
return false;
@ -76,7 +77,7 @@ bool DirectoryIterator::Iterate(const std::string& dir) {
if (dirent_ == nullptr)
return false;
if (::stat(PathName().c_str(), &stat_) != 0)
if (::stat(std::string(directory_ + Name()).c_str(), &stat_) != 0)
return false;
#endif
return true;
@ -92,7 +93,7 @@ bool DirectoryIterator::Next() {
if (dirent_ == nullptr)
return false;
return ::stat(PathName().c_str(), &stat_) == 0;
return ::stat(std::string(directory_ + Name()).c_str(), &stat_) == 0;
#endif
}
@ -111,17 +112,7 @@ std::string DirectoryIterator::Name() const {
return ToUtf8(data_.cFileName);
#else
RTC_DCHECK(dirent_);
return std::string(dirent_->d_name);
#endif
}
// returns the name of the file currently pointed to
std::string DirectoryIterator::PathName() const {
#if defined(WEBRTC_WIN)
return directory_ + "\\" + ToUtf8(data_.cFileName);
#else
RTC_DCHECK(dirent_);
return directory_ + "/" + dirent_->d_name;
return dirent_->d_name;
#endif
}