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

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

Issue 3001963002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Fuchsia fix 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),
67 fd_(-1),
68 lister_(0),
69 done_(false),
70 link_(NULL) {}
66 71
67 ~DirectoryListingEntry(); 72 ~DirectoryListingEntry();
68 73
69 ListType Next(DirectoryListing* listing); 74 ListType Next(DirectoryListing* listing);
70 75
71 DirectoryListingEntry* parent() const { return parent_; } 76 DirectoryListingEntry* parent() const { return parent_; }
72 77
73 LinkList* link() { return link_; } 78 LinkList* link() { return link_; }
74 79
75 void set_link(LinkList* link) { link_ = link; } 80 void set_link(LinkList* link) { link_ = link; }
76 81
77 void ResetLink(); 82 void ResetLink();
78 83
79 private: 84 private:
80 DirectoryListingEntry* parent_; 85 DirectoryListingEntry* parent_;
86 intptr_t fd_;
81 intptr_t lister_; 87 intptr_t lister_;
82 bool done_; 88 bool done_;
83 int path_length_; 89 int path_length_;
84 LinkList* link_; 90 LinkList* link_;
85 91
86 DISALLOW_COPY_AND_ASSIGN(DirectoryListingEntry); 92 DISALLOW_COPY_AND_ASSIGN(DirectoryListingEntry);
87 }; 93 };
88 94
89 class DirectoryListing { 95 class DirectoryListing {
90 public: 96 public:
91 DirectoryListing(const char* dir_name, bool recursive, bool follow_links) 97 DirectoryListing(Namespace* namespc,
92 : top_(NULL), 98 const char* dir_name,
99 bool recursive,
100 bool follow_links)
101 : namespc_(namespc),
102 top_(NULL),
93 error_(false), 103 error_(false),
94 recursive_(recursive), 104 recursive_(recursive),
95 follow_links_(follow_links) { 105 follow_links_(follow_links) {
96 if (!path_buffer_.Add(dir_name)) { 106 if (!path_buffer_.Add(dir_name)) {
97 error_ = true; 107 error_ = true;
98 } 108 }
99 Push(new DirectoryListingEntry(NULL)); 109 Push(new DirectoryListingEntry(NULL));
100 } 110 }
101 111
102 virtual ~DirectoryListing() { PopAll(); } 112 virtual ~DirectoryListing() { PopAll(); }
(...skipping 14 matching lines...) Expand all
117 } 127 }
118 128
119 bool IsEmpty() const { return top_ == NULL; } 129 bool IsEmpty() const { return top_ == NULL; }
120 130
121 void PopAll() { 131 void PopAll() {
122 while (!IsEmpty()) { 132 while (!IsEmpty()) {
123 Pop(); 133 Pop();
124 } 134 }
125 } 135 }
126 136
137 Namespace* namespc() const { return namespc_; }
138
127 DirectoryListingEntry* top() const { return top_; } 139 DirectoryListingEntry* top() const { return top_; }
128 140
129 bool recursive() const { return recursive_; } 141 bool recursive() const { return recursive_; }
130 142
131 bool follow_links() const { return follow_links_; } 143 bool follow_links() const { return follow_links_; }
132 144
133 const char* CurrentPath() { return path_buffer_.AsScopedString(); } 145 const char* CurrentPath() { return path_buffer_.AsScopedString(); }
134 146
135 PathBuffer& path_buffer() { return path_buffer_; } 147 PathBuffer& path_buffer() { return path_buffer_; }
136 148
137 bool error() const { return error_; } 149 bool error() const { return error_; }
138 150
139 private: 151 private:
140 PathBuffer path_buffer_; 152 PathBuffer path_buffer_;
153 Namespace* namespc_;
141 DirectoryListingEntry* top_; 154 DirectoryListingEntry* top_;
142 bool error_; 155 bool error_;
143 bool recursive_; 156 bool recursive_;
144 bool follow_links_; 157 bool follow_links_;
145 }; 158 };
146 159
147 class AsyncDirectoryListing : public ReferenceCounted<AsyncDirectoryListing>, 160 class AsyncDirectoryListing : public ReferenceCounted<AsyncDirectoryListing>,
148 public DirectoryListing { 161 public DirectoryListing {
149 public: 162 public:
150 enum Response { 163 enum Response {
151 kListFile = 0, 164 kListFile = 0,
152 kListDirectory = 1, 165 kListDirectory = 1,
153 kListLink = 2, 166 kListLink = 2,
154 kListError = 3, 167 kListError = 3,
155 kListDone = 4 168 kListDone = 4
156 }; 169 };
157 170
158 AsyncDirectoryListing(const char* dir_name, bool recursive, bool follow_links) 171 AsyncDirectoryListing(Namespace* namespc,
172 const char* dir_name,
173 bool recursive,
174 bool follow_links)
159 : ReferenceCounted(), 175 : ReferenceCounted(),
160 DirectoryListing(dir_name, recursive, follow_links), 176 DirectoryListing(namespc, dir_name, recursive, follow_links),
161 array_(NULL), 177 array_(NULL),
162 index_(0), 178 index_(0),
163 length_(0) {} 179 length_(0) {}
164 180
165 virtual bool HandleDirectory(const char* dir_name); 181 virtual bool HandleDirectory(const char* dir_name);
166 virtual bool HandleFile(const char* file_name); 182 virtual bool HandleFile(const char* file_name);
167 virtual bool HandleLink(const char* file_name); 183 virtual bool HandleLink(const char* file_name);
168 virtual bool HandleError(); 184 virtual bool HandleError();
169 virtual void HandleDone(); 185 virtual void HandleDone();
170 186
(...skipping 13 matching lines...) Expand all
184 intptr_t index_; 200 intptr_t index_;
185 intptr_t length_; 201 intptr_t length_;
186 202
187 friend class ReferenceCounted<AsyncDirectoryListing>; 203 friend class ReferenceCounted<AsyncDirectoryListing>;
188 DISALLOW_IMPLICIT_CONSTRUCTORS(AsyncDirectoryListing); 204 DISALLOW_IMPLICIT_CONSTRUCTORS(AsyncDirectoryListing);
189 }; 205 };
190 206
191 class SyncDirectoryListing : public DirectoryListing { 207 class SyncDirectoryListing : public DirectoryListing {
192 public: 208 public:
193 SyncDirectoryListing(Dart_Handle results, 209 SyncDirectoryListing(Dart_Handle results,
210 Namespace* namespc,
194 const char* dir_name, 211 const char* dir_name,
195 bool recursive, 212 bool recursive,
196 bool follow_links) 213 bool follow_links)
197 : DirectoryListing(dir_name, recursive, follow_links), 214 : DirectoryListing(namespc, dir_name, recursive, follow_links),
198 results_(results), 215 results_(results),
199 dart_error_(Dart_Null()) { 216 dart_error_(Dart_Null()) {
200 add_string_ = DartUtils::NewString("add"); 217 add_string_ = DartUtils::NewString("add");
201 directory_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "Directory"); 218 directory_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "Directory");
202 file_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "File"); 219 file_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "File");
203 link_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "Link"); 220 link_type_ = DartUtils::GetDartType(DartUtils::kIOLibURL, "Link");
204 } 221 }
205 virtual ~SyncDirectoryListing() {} 222 virtual ~SyncDirectoryListing() {}
206 virtual bool HandleDirectory(const char* dir_name); 223 virtual bool HandleDirectory(const char* dir_name);
207 virtual bool HandleFile(const char* file_name); 224 virtual bool HandleFile(const char* file_name);
(...skipping 12 matching lines...) Expand all
220 237
221 DISALLOW_ALLOCATION() 238 DISALLOW_ALLOCATION()
222 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncDirectoryListing); 239 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncDirectoryListing);
223 }; 240 };
224 241
225 class Directory { 242 class Directory {
226 public: 243 public:
227 enum ExistsResult { UNKNOWN, EXISTS, DOES_NOT_EXIST }; 244 enum ExistsResult { UNKNOWN, EXISTS, DOES_NOT_EXIST };
228 245
229 static void List(DirectoryListing* listing); 246 static void List(DirectoryListing* listing);
230 static ExistsResult Exists(const char* path); 247 static ExistsResult Exists(Namespace* namespc, const char* path);
231 248
232 // Returns the current working directory. The caller must call 249 // Returns the current working directory. The caller must call
233 // free() on the result. 250 // free() on the result.
234 static char* CurrentNoScope(); 251 static char* CurrentNoScope();
235 252
236 // Returns the current working directory. The returned string is allocated 253 // Returns the current working directory. The returned string is allocated
237 // with Dart_ScopeAllocate(). It lasts only as long as the current API scope. 254 // with Dart_ScopeAllocate(). It lasts only as long as the current API scope.
238 static const char* Current(); 255 static const char* Current(Namespace* namespc);
239 static const char* SystemTemp(); 256 static const char* SystemTemp(Namespace* namespc);
240 static const char* CreateTemp(const char* path); 257 static const char* CreateTemp(Namespace* namespc, const char* path);
241 // Set the system temporary directory. 258 // Set the system temporary directory.
242 static void SetSystemTemp(const char* path); 259 static void SetSystemTemp(const char* path);
243 static bool SetCurrent(const char* path); 260 static bool SetCurrent(Namespace* namespc, const char* path);
244 static bool Create(const char* path); 261 static bool Create(Namespace* namespc, const char* path);
245 static bool Delete(const char* path, bool recursive); 262 static bool Delete(Namespace* namespc, const char* path, bool recursive);
246 static bool Rename(const char* path, const char* new_path); 263 static bool Rename(
264 Namespace* namespc, const char* path, const char* new_path);
247 265
248 static CObject* CreateRequest(const CObjectArray& request); 266 static CObject* CreateRequest(const CObjectArray& request);
249 static CObject* DeleteRequest(const CObjectArray& request); 267 static CObject* DeleteRequest(const CObjectArray& request);
250 static CObject* ExistsRequest(const CObjectArray& request); 268 static CObject* ExistsRequest(const CObjectArray& request);
251 static CObject* CreateTempRequest(const CObjectArray& request); 269 static CObject* CreateTempRequest(const CObjectArray& request);
252 static CObject* CreateSystemTempRequest(const CObjectArray& request); 270 static CObject* CreateSystemTempRequest(const CObjectArray& request);
253 static CObject* ListStartRequest(const CObjectArray& request); 271 static CObject* ListStartRequest(const CObjectArray& request);
254 static CObject* ListNextRequest(const CObjectArray& request); 272 static CObject* ListNextRequest(const CObjectArray& request);
255 static CObject* ListStopRequest(const CObjectArray& request); 273 static CObject* ListStopRequest(const CObjectArray& request);
256 static CObject* RenameRequest(const CObjectArray& request); 274 static CObject* RenameRequest(const CObjectArray& request);
257 275
258 private: 276 private:
259 static char* system_temp_path_override_; 277 static char* system_temp_path_override_;
260 DISALLOW_ALLOCATION(); 278 DISALLOW_ALLOCATION();
261 DISALLOW_IMPLICIT_CONSTRUCTORS(Directory); 279 DISALLOW_IMPLICIT_CONSTRUCTORS(Directory);
262 }; 280 };
263 281
264 } // namespace bin 282 } // namespace bin
265 } // namespace dart 283 } // namespace dart
266 284
267 #endif // RUNTIME_BIN_DIRECTORY_H_ 285 #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