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}
diff --git a/rtc_base/unixfilesystem.cc b/rtc_base/unixfilesystem.cc
index ee9e3f0..2a941e2 100644
--- a/rtc_base/unixfilesystem.cc
+++ b/rtc_base/unixfilesystem.cc
@@ -38,6 +38,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
+#include "rtc_base/pathutils.h"
namespace rtc {
@@ -45,39 +46,47 @@
UnixFilesystem::~UnixFilesystem() {}
-bool UnixFilesystem::DeleteFile(const std::string& filename) {
- RTC_LOG(LS_INFO) << "Deleting file:" << filename;
+bool UnixFilesystem::DeleteFile(const Pathname& filename) {
+ RTC_LOG(LS_INFO) << "Deleting file:" << filename.pathname();
if (!IsFile(filename)) {
RTC_DCHECK(IsFile(filename));
return false;
}
- return ::unlink(filename.c_str()) == 0;
+ return ::unlink(filename.pathname().c_str()) == 0;
}
-bool UnixFilesystem::MoveFile(const std::string& old_path,
- const std::string& new_path) {
+bool UnixFilesystem::MoveFile(const Pathname& old_path,
+ const Pathname& new_path) {
if (!IsFile(old_path)) {
RTC_DCHECK(IsFile(old_path));
return false;
}
- RTC_LOG(LS_VERBOSE) << "Moving " << old_path << " to " << new_path;
- if (rename(old_path.c_str(), new_path.c_str()) != 0) {
+ RTC_LOG(LS_VERBOSE) << "Moving " << old_path.pathname() << " to "
+ << new_path.pathname();
+ if (rename(old_path.pathname().c_str(), new_path.pathname().c_str()) != 0) {
return false;
}
return true;
}
-bool UnixFilesystem::IsFile(const std::string& pathname) {
+bool UnixFilesystem::IsFolder(const Pathname& path) {
struct stat st;
- int res = ::stat(pathname.c_str(), &st);
+ if (stat(path.pathname().c_str(), &st) < 0)
+ return false;
+ return S_ISDIR(st.st_mode);
+}
+
+bool UnixFilesystem::IsFile(const Pathname& pathname) {
+ struct stat st;
+ int res = ::stat(pathname.pathname().c_str(), &st);
// Treat symlinks, named pipes, etc. all as files.
return res == 0 && !S_ISDIR(st.st_mode);
}
-bool UnixFilesystem::GetFileSize(const std::string& pathname, size_t* size) {
+bool UnixFilesystem::GetFileSize(const Pathname& pathname, size_t* size) {
struct stat st;
- if (::stat(pathname.c_str(), &st) != 0)
+ if (::stat(pathname.pathname().c_str(), &st) != 0)
return false;
*size = st.st_size;
return true;