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

Side by Side Diff: mojo/dart/embedder/io/file_patch.dart

Issue 1539843004: Support some file operations in dart:io under mojo (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:_mojo_services/mojo/files/types.mojom.dart' as types;
6
5 // 7 //
6 // Implementation of File and RandomAccessFile for Mojo. 8 // Implementation of Directory, File, and RandomAccessFile for Mojo.
7 // 9 //
8 10
9 // TODO(johnmccutchan): Implement. 11 OSError _OSErrorFromError(types.Error error) {
12 assert(error != null);
13 return new OSError(error.toString(), error.toJson());
14 }
15
16 String _ensurePathIsRelative(String path) {
17 while (path.startsWith('/')) {
18 // Trim off the leading '/'.
19 path = path.substring(1);
20 }
21 return path;
22 }
23
24 patch class _Directory {
25 // We start at the root of the file system.
26 static String _currentDirectoryPath = '/';
27
28 /* patch */ Future<Directory> create({bool recursive: false}) async {
29 if (recursive) {
30 return exists().then((exists) {
31 if (exists) return this;
32 if (path != parent.path) {
33 return parent.create(recursive: true).then((_) {
34 return create();
35 });
36 } else {
37 return create();
38 }
39 });
40 }
41 DirectoryProxy rootDirectory = await _getRootDirectory();
42 int flags =
43 types.kOpenFlagRead | types.kOpenFlagWrite | types.kOpenFlagCreate;
44 var response =
45 await rootDirectory.ptr.openDirectory(_ensurePathIsRelative(path),
zra 2015/12/18 22:51:46 For IPC calls deep in library implementations, it
Cutch 2015/12/18 23:05:20 Done here and elsewhere.
46 null,
47 flags);
48 if (response.error != types.Error.ok) {
49 throw _OSErrorFromError(response.error);
50 }
51 return this;
52 }
53
54 /* patch */ Future<Directory> createTemp([String prefix]) async {
55 DirectoryProxy rootDirectory = await _getRootDirectory();
56 // Create directory and fail if it already exists.
57 int flags = types.kOpenFlagRead | types.kOpenFlagWrite |
58 types.kOpenFlagCreate | types.kOpenFlagExclusive;
59 String tempPath = '$path/$prefix';
60 while (true) {
61 print(tempPath);
zra 2015/12/18 22:51:46 debug print?
Cutch 2015/12/18 23:05:20 Done.
62 var response = await rootDirectory.ptr.openDirectory(tempPath, null, flags );
zra 2015/12/18 22:51:46 long line
Cutch 2015/12/18 23:05:20 Done.
63 if (response.error == types.Error.ok) {
64 // Success.
65 break;
66 }
67 // Alter the path and try again.
68 // TODO(johnmccutchan): Append a randomly generated character.
69 tempPath = tempPath + 'a';
70 }
71 return new Directory(tempPath);
72 }
73
74 /* patch */ Future<bool> exists() async {
75 DirectoryProxy rootDirectory = await _getRootDirectory();
76 int flags = types.kOpenFlagRead | types.kOpenFlagWrite;
77 var response =
78 await rootDirectory.ptr.openDirectory(_ensurePathIsRelative(path),
79 null,
80 flags);
81 // If we can open it, it exists.
82 return response.error == types.Error.ok;
83 }
84
85 /* patch */ static _current() {
86 return _currentDirectoryPath;
87 }
88
89 /* patch */ static _setCurrent(path) {
90 _currentDirectoryPath = path;
91 }
92
93 /* patch */ static _createTemp(String path) {
zra 2015/12/18 22:51:46 What are these empty functions for? Should they th
Cutch 2015/12/18 23:05:20 These are patches that will be necessary. I've add
94 }
95
96 /* patch */ static String _systemTemp() {
97 return 'tmp';
98 }
99
100 /* patch */ static _exists(String path) {
101 }
102
103 /* patch */ static _create(String path) {
104 }
105
106 /* patch */ static _deleteNative(String path, bool recursive) {
107 }
108
109 /* patch */ static _rename(String path, String newPath) {
110 }
111
112 /* patch */ static List _list(String path, bool recursive, bool followLinks) {
113 }
114 }
115
116
117 patch class _File {
118 /* patch */ Future<bool> exists() async {
119 DirectoryProxy rootDirectory = await _getRootDirectory();
120 int flags = types.kOpenFlagRead;
121 var response =
122 await rootDirectory.ptr.openFile(_ensurePathIsRelative(path),
123 null,
124 flags);
125 // If we can open it, it exists.
126 return response.error == types.Error.ok;
127 }
128
129 Future<File> create({bool recursive: false}) async {
130 if (recursive) {
131 // Create any parent directories.
132 await parent.create(recursive: true);
133 }
134 DirectoryProxy rootDirectory = await _getRootDirectory();
135 int flags = types.kOpenFlagWrite | types.kOpenFlagCreate;
136 print(_ensurePathIsRelative(path));
137 var response =
138 await rootDirectory.ptr.openFile(_ensurePathIsRelative(path),
139 null,
140 flags);
141 if (response.error != types.Error.ok) {
142 throw _OSErrorFromError(response.error);
143 }
144 return this;
145 }
146
147 /* patch */ static _exists(String path) {
148 }
149
150 /* patch */ static _create(String path) {
151 }
152
153 /* patch */ static _createLink(String path, String target) {
154 }
155
156 /* patch */ static _linkTarget(String path) {
157 }
158
159 /* patch */ static _deleteNative(String path) {
160 }
161
162 /* patch */ static _deleteLinkNative(String path) {
163 }
164
165 /* patch */ static _rename(String oldPath, String newPath) {
166 }
167
168 /* patch */ static _renameLink(String oldPath, String newPath) {
169 }
170
171 /* patch */ static _copy(String oldPath, String newPath) {
172 }
173
174 /* patch */ static _lengthFromPath(String path) {
175 }
176
177 /* patch */ static _lastModified(String path) {
178 }
179
180 /* patch */ static _open(String path, int mode) {
181 }
182
183 /* patch */ static int _openStdio(int fd) {
184 }
185 }
186
187 patch class FileStat {
188 /* patch */ static _statSync(String path) {
189 }
190 }
191
192
193 patch class FileSystemEntity {
194 /* patch */ static _getType(String path, bool followLinks) {
195 }
196 /* patch */ static _identical(String path1, String path2) {
197 }
198 /* patch */ static _resolveSymbolicLinks(String path) {
199 }
200 }
201
202 patch class _Link {
203 }
204
205
206 patch class _RandomAccessFile {
207 /* patch */ static int _close(int id) {
208 }
209
210 /* patch */ static int _getFD(int id) {
211 }
212
213 /* patch */ static _readByte(int id) {
214 }
215
216 /* patch */ static _read(int id, int bytes) {
217 }
218
219 /* patch */ static _readInto(int id, List<int> buffer, int start, int end) {
220 }
221
222 /* patch */ static _writeByte(int id, int value) {
223 }
224
225 /* patch */ static _writeFrom(int id, List<int> buffer, int start, int end) {
226 }
227
228 /* patch */ static _position(int id) {
229 }
230
231 /* patch */ static _setPosition(int id, int position) {
232 }
233
234 /* patch */ static _truncate(int id, int length) {
235 }
236
237 /* patch */ static _length(int id) {
238 }
239
240 /* patch */ static _flush(int id) {
241 }
242
243 /* patch */ static _lock(int id, int lock, int start, int end) {
244 }
245 }
OLDNEW
« no previous file with comments | « no previous file | mojo/dart/embedder/io/mojo_patch.dart » ('j') | mojo/dart/embedder/io/mojo_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698