| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved. | 
| 3  * | 3  * | 
| 4  *  Use of this source code is governed by a BSD-style license | 4  *  Use of this source code is governed by a BSD-style license | 
| 5  *  that can be found in the LICENSE file in the root of the source | 5  *  that can be found in the LICENSE file in the root of the source | 
| 6  *  tree. An additional intellectual property rights grant can be found | 6  *  tree. An additional intellectual property rights grant can be found | 
| 7  *  in the file PATENTS.  All contributing project authors may | 7  *  in the file PATENTS.  All contributing project authors may | 
| 8  *  be found in the AUTHORS file in the root of the source tree. | 8  *  be found in the AUTHORS file in the root of the source tree. | 
| 9  */ | 9  */ | 
| 10 | 10 | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 33 | 33 | 
| 34 // A DirectoryIterator is created with a given directory. It originally points | 34 // A DirectoryIterator is created with a given directory. It originally points | 
| 35 // to the first file in the directory, and can be advanecd with Next(). This | 35 // to the first file in the directory, and can be advanecd with Next(). This | 
| 36 // allows you to get information about each file. | 36 // allows you to get information about each file. | 
| 37 | 37 | 
| 38   // Constructor | 38   // Constructor | 
| 39 DirectoryIterator::DirectoryIterator() | 39 DirectoryIterator::DirectoryIterator() | 
| 40 #ifdef WEBRTC_WIN | 40 #ifdef WEBRTC_WIN | 
| 41     : handle_(INVALID_HANDLE_VALUE) { | 41     : handle_(INVALID_HANDLE_VALUE) { | 
| 42 #else | 42 #else | 
| 43     : dir_(NULL), dirent_(NULL) { | 43     : dir_(nullptr), | 
|  | 44       dirent_(nullptr){ | 
| 44 #endif | 45 #endif | 
| 45 } | 46 } | 
| 46 | 47 | 
| 47   // Destructor | 48   // Destructor | 
| 48 DirectoryIterator::~DirectoryIterator() { | 49 DirectoryIterator::~DirectoryIterator() { | 
| 49 #if defined(WEBRTC_WIN) | 50 #if defined(WEBRTC_WIN) | 
| 50   if (handle_ != INVALID_HANDLE_VALUE) | 51   if (handle_ != INVALID_HANDLE_VALUE) | 
| 51     ::FindClose(handle_); | 52     ::FindClose(handle_); | 
| 52 #else | 53 #else | 
| 53   if (dir_) | 54   if (dir_) | 
| 54     closedir(dir_); | 55     closedir(dir_); | 
| 55 #endif | 56 #endif | 
| 56 } | 57 } | 
| 57 | 58 | 
| 58   // Starts traversing a directory. | 59   // Starts traversing a directory. | 
| 59   // dir is the directory to traverse | 60   // dir is the directory to traverse | 
| 60   // returns true if the directory exists and is valid | 61   // returns true if the directory exists and is valid | 
| 61 bool DirectoryIterator::Iterate(const Pathname &dir) { | 62 bool DirectoryIterator::Iterate(const Pathname &dir) { | 
| 62   directory_ = dir.pathname(); | 63   directory_ = dir.pathname(); | 
| 63 #if defined(WEBRTC_WIN) | 64 #if defined(WEBRTC_WIN) | 
| 64   if (handle_ != INVALID_HANDLE_VALUE) | 65   if (handle_ != INVALID_HANDLE_VALUE) | 
| 65     ::FindClose(handle_); | 66     ::FindClose(handle_); | 
| 66   std::string d = dir.pathname() + '*'; | 67   std::string d = dir.pathname() + '*'; | 
| 67   handle_ = ::FindFirstFile(ToUtf16(d).c_str(), &data_); | 68   handle_ = ::FindFirstFile(ToUtf16(d).c_str(), &data_); | 
| 68   if (handle_ == INVALID_HANDLE_VALUE) | 69   if (handle_ == INVALID_HANDLE_VALUE) | 
| 69     return false; | 70     return false; | 
| 70 #else | 71 #else | 
| 71   if (dir_ != NULL) | 72   if (dir_ != nullptr) | 
| 72     closedir(dir_); | 73     closedir(dir_); | 
| 73   dir_ = ::opendir(directory_.c_str()); | 74   dir_ = ::opendir(directory_.c_str()); | 
| 74   if (dir_ == NULL) | 75   if (dir_ == nullptr) | 
| 75     return false; | 76     return false; | 
| 76   dirent_ = readdir(dir_); | 77   dirent_ = readdir(dir_); | 
| 77   if (dirent_ == NULL) | 78   if (dirent_ == nullptr) | 
| 78     return false; | 79     return false; | 
| 79 | 80 | 
| 80   if (::stat(std::string(directory_ + Name()).c_str(), &stat_) != 0) | 81   if (::stat(std::string(directory_ + Name()).c_str(), &stat_) != 0) | 
| 81     return false; | 82     return false; | 
| 82 #endif | 83 #endif | 
| 83   return true; | 84   return true; | 
| 84 } | 85 } | 
| 85 | 86 | 
| 86   // Advances to the next file | 87   // Advances to the next file | 
| 87   // returns true if there were more files in the directory. | 88   // returns true if there were more files in the directory. | 
| 88 bool DirectoryIterator::Next() { | 89 bool DirectoryIterator::Next() { | 
| 89 #if defined(WEBRTC_WIN) | 90 #if defined(WEBRTC_WIN) | 
| 90   return ::FindNextFile(handle_, &data_) == TRUE; | 91   return ::FindNextFile(handle_, &data_) == TRUE; | 
| 91 #else | 92 #else | 
| 92   dirent_ = ::readdir(dir_); | 93   dirent_ = ::readdir(dir_); | 
| 93   if (dirent_ == NULL) | 94   if (dirent_ == nullptr) | 
| 94     return false; | 95     return false; | 
| 95 | 96 | 
| 96   return ::stat(std::string(directory_ + Name()).c_str(), &stat_) == 0; | 97   return ::stat(std::string(directory_ + Name()).c_str(), &stat_) == 0; | 
| 97 #endif | 98 #endif | 
| 98 } | 99 } | 
| 99 | 100 | 
| 100   // returns true if the file currently pointed to is a directory | 101   // returns true if the file currently pointed to is a directory | 
| 101 bool DirectoryIterator::IsDirectory() const { | 102 bool DirectoryIterator::IsDirectory() const { | 
| 102 #if defined(WEBRTC_WIN) | 103 #if defined(WEBRTC_WIN) | 
| 103   return (data_.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FALSE; | 104   return (data_.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FALSE; | 
| 104 #else | 105 #else | 
| 105   return S_ISDIR(stat_.st_mode); | 106   return S_ISDIR(stat_.st_mode); | 
| 106 #endif | 107 #endif | 
| 107 } | 108 } | 
| 108 | 109 | 
| 109   // returns the name of the file currently pointed to | 110   // returns the name of the file currently pointed to | 
| 110 std::string DirectoryIterator::Name() const { | 111 std::string DirectoryIterator::Name() const { | 
| 111 #if defined(WEBRTC_WIN) | 112 #if defined(WEBRTC_WIN) | 
| 112   return ToUtf8(data_.cFileName); | 113   return ToUtf8(data_.cFileName); | 
| 113 #else | 114 #else | 
| 114   RTC_DCHECK(dirent_); | 115   RTC_DCHECK(dirent_); | 
| 115   return dirent_->d_name; | 116   return dirent_->d_name; | 
| 116 #endif | 117 #endif | 
| 117 } | 118 } | 
| 118 | 119 | 
| 119 FilesystemInterface* Filesystem::default_filesystem_ = NULL; | 120 FilesystemInterface* Filesystem::default_filesystem_ = nullptr; | 
| 120 | 121 | 
| 121 FilesystemInterface *Filesystem::EnsureDefaultFilesystem() { | 122 FilesystemInterface *Filesystem::EnsureDefaultFilesystem() { | 
| 122   if (!default_filesystem_) { | 123   if (!default_filesystem_) { | 
| 123 #if defined(WEBRTC_WIN) | 124 #if defined(WEBRTC_WIN) | 
| 124     default_filesystem_ = new Win32Filesystem(); | 125     default_filesystem_ = new Win32Filesystem(); | 
| 125 #else | 126 #else | 
| 126     default_filesystem_ = new UnixFilesystem(); | 127     default_filesystem_ = new UnixFilesystem(); | 
| 127 #endif | 128 #endif | 
| 128   } | 129   } | 
| 129   return default_filesystem_; | 130   return default_filesystem_; | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 160   } | 161   } | 
| 161   delete di; | 162   delete di; | 
| 162   return success; | 163   return success; | 
| 163 } | 164 } | 
| 164 | 165 | 
| 165 bool FilesystemInterface::DeleteFolderAndContents(const Pathname& folder) { | 166 bool FilesystemInterface::DeleteFolderAndContents(const Pathname& folder) { | 
| 166   return DeleteFolderContents(folder) && DeleteEmptyFolder(folder); | 167   return DeleteFolderContents(folder) && DeleteEmptyFolder(folder); | 
| 167 } | 168 } | 
| 168 | 169 | 
| 169 }  // namespace rtc | 170 }  // namespace rtc | 
| OLD | NEW | 
|---|