Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: runtime/bin/directory.h

Issue 3007703002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Remove namespace_unsupported.cc Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/directory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef RUNTIME_BIN_DIRECTORY_H_ 5 #ifndef RUNTIME_BIN_DIRECTORY_H_
6 #define RUNTIME_BIN_DIRECTORY_H_ 6 #define RUNTIME_BIN_DIRECTORY_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/dartutils.h" 9 #include "bin/dartutils.h"
10 #include "bin/namespace.h"
10 #include "bin/reference_counting.h" 11 #include "bin/reference_counting.h"
11 #include "bin/thread.h" 12 #include "bin/thread.h"
12 #include "platform/globals.h" 13 #include "platform/globals.h"
13 14
14 namespace dart { 15 namespace dart {
15 namespace bin { 16 namespace bin {
16 17
17 enum ListType { 18 enum ListType {
18 kListFile = 0, 19 kListFile = 0,
19 kListDirectory = 1, 20 kListDirectory = 1,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // directory listing. By using DirectoryListingEntry as stack elements, a 56 // directory listing. By using DirectoryListingEntry as stack elements, a
56 // directory listing can be paused e.g. when a buffer is full, and resumed 57 // directory listing can be paused e.g. when a buffer is full, and resumed
57 // later on. 58 // later on.
58 // 59 //
59 // The stack is managed by the DirectoryListing's PathBuffer. Each 60 // The stack is managed by the DirectoryListing's PathBuffer. Each
60 // DirectoryListingEntry stored a entry-length, that it'll reset the PathBuffer 61 // DirectoryListingEntry stored a entry-length, that it'll reset the PathBuffer
61 // to on each call to Next. 62 // to on each call to Next.
62 class DirectoryListingEntry { 63 class DirectoryListingEntry {
63 public: 64 public:
64 explicit DirectoryListingEntry(DirectoryListingEntry* parent) 65 explicit DirectoryListingEntry(DirectoryListingEntry* parent)
65 : parent_(parent), lister_(0), done_(false), link_(NULL) {} 66 : parent_(parent), fd_(-1), lister_(0), done_(false), link_(NULL) {}
66 67
67 ~DirectoryListingEntry(); 68 ~DirectoryListingEntry();
68 69
69 ListType Next(DirectoryListing* listing); 70 ListType Next(DirectoryListing* listing);
70 71
71 DirectoryListingEntry* parent() const { return parent_; } 72 DirectoryListingEntry* parent() const { return parent_; }
72 73
73 LinkList* link() { return link_; } 74 LinkList* link() { return link_; }
74 75
75 void set_link(LinkList* link) { link_ = link; } 76 void set_link(LinkList* link) { link_ = link; }
76 77
77 void ResetLink(); 78 void ResetLink();
78 79
79 private: 80 private:
80 DirectoryListingEntry* parent_; 81 DirectoryListingEntry* parent_;
82 intptr_t fd_;
81 intptr_t lister_; 83 intptr_t lister_;
82 bool done_; 84 bool done_;
83 int path_length_; 85 int path_length_;
84 LinkList* link_; 86 LinkList* link_;
85 87
86 DISALLOW_COPY_AND_ASSIGN(DirectoryListingEntry); 88 DISALLOW_COPY_AND_ASSIGN(DirectoryListingEntry);
87 }; 89 };
88 90
89 class DirectoryListing { 91 class DirectoryListing {
90 public: 92 public:
91 DirectoryListing(const char* dir_name, bool recursive, bool follow_links) 93 DirectoryListing(Namespace* namespc,
92 : top_(NULL), 94 const char* dir_name,
95 bool recursive,
96 bool follow_links)
97 : namespc_(namespc),
98 top_(NULL),
93 error_(false), 99 error_(false),
94 recursive_(recursive), 100 recursive_(recursive),
95 follow_links_(follow_links) { 101 follow_links_(follow_links) {
96 if (!path_buffer_.Add(dir_name)) { 102 if (!path_buffer_.Add(dir_name)) {
97 error_ = true; 103 error_ = true;
98 } 104 }
99 Push(new DirectoryListingEntry(NULL)); 105 Push(new DirectoryListingEntry(NULL));
100 } 106 }
101 107
102 virtual ~DirectoryListing() { PopAll(); } 108 virtual ~DirectoryListing() { PopAll(); }
(...skipping 14 matching lines...) Expand all
117 } 123 }
118 124
119 bool IsEmpty() const { return top_ == NULL; } 125 bool IsEmpty() const { return top_ == NULL; }
120 126
121 void PopAll() { 127 void PopAll() {
122 while (!IsEmpty()) { 128 while (!IsEmpty()) {
123 Pop(); 129 Pop();
124 } 130 }
125 } 131 }
126 132
133 Namespace* namespc() const { return namespc_; }
134
127 DirectoryListingEntry* top() const { return top_; } 135 DirectoryListingEntry* top() const { return top_; }
128 136
129 bool recursive() const { return recursive_; } 137 bool recursive() const { return recursive_; }
130 138
131 bool follow_links() const { return follow_links_; } 139 bool follow_links() const { return follow_links_; }
132 140
133 const char* CurrentPath() { return path_buffer_.AsScopedString(); } 141 const char* CurrentPath() { return path_buffer_.AsScopedString(); }
134 142
135 PathBuffer& path_buffer() { return path_buffer_; } 143 PathBuffer& path_buffer() { return path_buffer_; }
136 144
137 bool error() const { return error_; } 145 bool error() const { return error_; }
138 146
139 private: 147 private:
140 PathBuffer path_buffer_; 148 PathBuffer path_buffer_;
149 Namespace* namespc_;
141 DirectoryListingEntry* top_; 150 DirectoryListingEntry* top_;
142 bool error_; 151 bool error_;
143 bool recursive_; 152 bool recursive_;
144 bool follow_links_; 153 bool follow_links_;
145 }; 154 };
146 155
147 class AsyncDirectoryListing : public ReferenceCounted<AsyncDirectoryListing>, 156 class AsyncDirectoryListing : public ReferenceCounted<AsyncDirectoryListing>,
148 public DirectoryListing { 157 public DirectoryListing {
149 public: 158 public:
150 enum Response { 159 enum Response {
151 kListFile = 0, 160 kListFile = 0,
152 kListDirectory = 1, 161 kListDirectory = 1,
153 kListLink = 2, 162 kListLink = 2,
154 kListError = 3, 163 kListError = 3,
155 kListDone = 4 164 kListDone = 4
156 }; 165 };
157 166
158 AsyncDirectoryListing(const char* dir_name, bool recursive, bool follow_links) 167 AsyncDirectoryListing(Namespace* namespc,
168 const char* dir_name,
169 bool recursive,
170 bool follow_links)
159 : ReferenceCounted(), 171 : ReferenceCounted(),
160 DirectoryListing(dir_name, recursive, follow_links), 172 DirectoryListing(namespc, dir_name, recursive, follow_links),
161 array_(NULL), 173 array_(NULL),
162 index_(0), 174 index_(0),
163 length_(0) {} 175 length_(0) {}
164 176
165 virtual bool HandleDirectory(const char* dir_name); 177 virtual bool HandleDirectory(const char* dir_name);
166 virtual bool HandleFile(const char* file_name); 178 virtual bool HandleFile(const char* file_name);
167 virtual bool HandleLink(const char* file_name); 179 virtual bool HandleLink(const char* file_name);
168 virtual bool HandleError(); 180 virtual bool HandleError();
169 virtual void HandleDone(); 181 virtual void HandleDone();
170 182
(...skipping 13 matching lines...) Expand all
184 intptr_t index_; 196 intptr_t index_;
185 intptr_t length_; 197 intptr_t length_;
186 198
187 friend class ReferenceCounted<AsyncDirectoryListing>; 199 friend class ReferenceCounted<AsyncDirectoryListing>;
188 DISALLOW_IMPLICIT_CONSTRUCTORS(AsyncDirectoryListing); 200 DISALLOW_IMPLICIT_CONSTRUCTORS(AsyncDirectoryListing);
189 }; 201 };
190 202
191 class SyncDirectoryListing : public DirectoryListing { 203 class SyncDirectoryListing : public DirectoryListing {
192 public: 204 public:
193 SyncDirectoryListing(Dart_Handle results, 205 SyncDirectoryListing(Dart_Handle results,
206 Namespace* namespc,
194 const char* dir_name, 207 const char* dir_name,
195 bool recursive, 208 bool recursive,
196 bool follow_links) 209 bool follow_links)
197 : DirectoryListing(dir_name, recursive, follow_links), 210 : DirectoryListing(namespc, dir_name, recursive, follow_links),
198 results_(results), 211 results_(results),
199 dart_error_(Dart_Null()) { 212 dart_error_(Dart_Null()) {
200 add_string_ = DartUtils::NewString("add"); 213 add_string_ = DartUtils::NewString("add");
201 directory_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "Directory"); 214 directory_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "Directory");
202 file_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "File"); 215 file_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "File");
203 link_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "Link"); 216 link_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "Link");
204 } 217 }
205 virtual ~SyncDirectoryListing() {} 218 virtual ~SyncDirectoryListing() {}
206 virtual bool HandleDirectory(const char* dir_name); 219 virtual bool HandleDirectory(const char* dir_name);
207 virtual bool HandleFile(const char* file_name); 220 virtual bool HandleFile(const char* file_name);
(...skipping 12 matching lines...) Expand all
220 233
221 DISALLOW_ALLOCATION() 234 DISALLOW_ALLOCATION()
222 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncDirectoryListing); 235 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncDirectoryListing);
223 }; 236 };
224 237
225 class Directory { 238 class Directory {
226 public: 239 public:
227 enum ExistsResult { UNKNOWN, EXISTS, DOES_NOT_EXIST }; 240 enum ExistsResult { UNKNOWN, EXISTS, DOES_NOT_EXIST };
228 241
229 static void List(DirectoryListing* listing); 242 static void List(DirectoryListing* listing);
230 static ExistsResult Exists(const char* path); 243 static ExistsResult Exists(Namespace* namespc, const char* path);
231 244
232 // Returns the current working directory. The caller must call 245 // Returns the current working directory. The caller must call
233 // free() on the result. 246 // free() on the result.
234 static char* CurrentNoScope(); 247 static char* CurrentNoScope();
235 248
236 // Returns the current working directory. The returned string is allocated 249 // Returns the current working directory. The returned string is allocated
237 // with Dart_ScopeAllocate(). It lasts only as long as the current API scope. 250 // with Dart_ScopeAllocate(). It lasts only as long as the current API scope.
238 static const char* Current(); 251 static const char* Current(Namespace* namespc);
239 static const char* SystemTemp(); 252 static const char* SystemTemp(Namespace* namespc);
240 static const char* CreateTemp(const char* path); 253 static const char* CreateTemp(Namespace* namespc, const char* path);
241 // Set the system temporary directory. 254 // Set the system temporary directory.
242 static void SetSystemTemp(const char* path); 255 static void SetSystemTemp(const char* path);
243 static bool SetCurrent(const char* path); 256 static bool SetCurrent(Namespace* namespc, const char* path);
244 static bool Create(const char* path); 257 static bool Create(Namespace* namespc, const char* path);
245 static bool Delete(const char* path, bool recursive); 258 static bool Delete(Namespace* namespc, const char* path, bool recursive);
246 static bool Rename(const char* path, const char* new_path); 259 static bool Rename(Namespace* namespc,
260 const char* path,
261 const char* new_path);
247 262
248 static CObject* CreateRequest(const CObjectArray& request); 263 static CObject* CreateRequest(const CObjectArray& request);
249 static CObject* DeleteRequest(const CObjectArray& request); 264 static CObject* DeleteRequest(const CObjectArray& request);
250 static CObject* ExistsRequest(const CObjectArray& request); 265 static CObject* ExistsRequest(const CObjectArray& request);
251 static CObject* CreateTempRequest(const CObjectArray& request); 266 static CObject* CreateTempRequest(const CObjectArray& request);
252 static CObject* CreateSystemTempRequest(const CObjectArray& request); 267 static CObject* CreateSystemTempRequest(const CObjectArray& request);
253 static CObject* ListStartRequest(const CObjectArray& request); 268 static CObject* ListStartRequest(const CObjectArray& request);
254 static CObject* ListNextRequest(const CObjectArray& request); 269 static CObject* ListNextRequest(const CObjectArray& request);
255 static CObject* ListStopRequest(const CObjectArray& request); 270 static CObject* ListStopRequest(const CObjectArray& request);
256 static CObject* RenameRequest(const CObjectArray& request); 271 static CObject* RenameRequest(const CObjectArray& request);
257 272
258 private: 273 private:
259 static char* system_temp_path_override_; 274 static char* system_temp_path_override_;
260 DISALLOW_ALLOCATION(); 275 DISALLOW_ALLOCATION();
261 DISALLOW_IMPLICIT_CONSTRUCTORS(Directory); 276 DISALLOW_IMPLICIT_CONSTRUCTORS(Directory);
262 }; 277 };
263 278
264 } // namespace bin 279 } // namespace bin
265 } // namespace dart 280 } // namespace dart
266 281
267 #endif // RUNTIME_BIN_DIRECTORY_H_ 282 #endif // RUNTIME_BIN_DIRECTORY_H_
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/directory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698