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

Side by Side Diff: sdk/lib/io/link.dart

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 | « sdk/lib/io/io_sources.gni ('k') | sdk/lib/io/namespace_impl.dart » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.io; 5 part of dart.io;
6 6
7 /** 7 /**
8 * [Link] objects are references to filesystem links. 8 * [Link] objects are references to filesystem links.
9 * 9 *
10 */ 10 */
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 161
162 Link get absolute => new Link(_absolutePath); 162 Link get absolute => new Link(_absolutePath);
163 163
164 Future<Link> create(String target, {bool recursive: false}) { 164 Future<Link> create(String target, {bool recursive: false}) {
165 if (Platform.isWindows) { 165 if (Platform.isWindows) {
166 target = _makeWindowsLinkTarget(target); 166 target = _makeWindowsLinkTarget(target);
167 } 167 }
168 var result = 168 var result =
169 recursive ? parent.create(recursive: true) : new Future.value(null); 169 recursive ? parent.create(recursive: true) : new Future.value(null);
170 return result 170 return result
171 .then((_) => _IOService._dispatch(_FILE_CREATE_LINK, [path, target])) 171 .then((_) => _File._dispatchWithNamespace(_FILE_CREATE_LINK, [null, path , target]))
172 .then((response) { 172 .then((response) {
173 if (_isErrorResponse(response)) { 173 if (_isErrorResponse(response)) {
174 throw _exceptionFromResponse( 174 throw _exceptionFromResponse(
175 response, "Cannot create link to target '$target'", path); 175 response, "Cannot create link to target '$target'", path);
176 } 176 }
177 return this; 177 return this;
178 }); 178 });
179 } 179 }
180 180
181 void createSync(String target, {bool recursive: false}) { 181 void createSync(String target, {bool recursive: false}) {
182 if (recursive) { 182 if (recursive) {
183 parent.createSync(recursive: true); 183 parent.createSync(recursive: true);
184 } 184 }
185 if (Platform.isWindows) { 185 if (Platform.isWindows) {
186 target = _makeWindowsLinkTarget(target); 186 target = _makeWindowsLinkTarget(target);
187 } 187 }
188 var result = _File._createLink(path, target); 188 var result = _File._createLink(_Namespace._namespace, path, target);
189 throwIfError(result, "Cannot create link", path); 189 throwIfError(result, "Cannot create link", path);
190 } 190 }
191 191
192 // Put target into the form "\??\C:\my\target\dir". 192 // Put target into the form "\??\C:\my\target\dir".
193 String _makeWindowsLinkTarget(String target) { 193 String _makeWindowsLinkTarget(String target) {
194 Uri base = new Uri.file('${Directory.current.path}\\'); 194 Uri base = new Uri.file('${Directory.current.path}\\');
195 Uri link = new Uri.file(path); 195 Uri link = new Uri.file(path);
196 Uri destination = new Uri.file(target); 196 Uri destination = new Uri.file(target);
197 String result = base.resolveUri(link).resolveUri(destination).toFilePath(); 197 String result = base.resolveUri(link).resolveUri(destination).toFilePath();
198 if (result.length > 3 && result[1] == ':' && result[2] == '\\') { 198 if (result.length > 3 && result[1] == ':' && result[2] == '\\') {
(...skipping 19 matching lines...) Expand all
218 // Atomically changing a link can be done by creating the new link, with 218 // Atomically changing a link can be done by creating the new link, with
219 // a different name, and using the rename() posix call to move it to 219 // a different name, and using the rename() posix call to move it to
220 // the old name atomically. 220 // the old name atomically.
221 return delete().then<Link>((_) => create(target)); 221 return delete().then<Link>((_) => create(target));
222 } 222 }
223 223
224 Future<Link> _delete({bool recursive: false}) { 224 Future<Link> _delete({bool recursive: false}) {
225 if (recursive) { 225 if (recursive) {
226 return new Directory(path).delete(recursive: true).then((_) => this); 226 return new Directory(path).delete(recursive: true).then((_) => this);
227 } 227 }
228 return _IOService._dispatch(_FILE_DELETE_LINK, [path]).then((response) { 228 return _File._dispatchWithNamespace(_FILE_DELETE_LINK, [null, path])
229 .then((response) {
229 if (_isErrorResponse(response)) { 230 if (_isErrorResponse(response)) {
230 throw _exceptionFromResponse(response, "Cannot delete link", path); 231 throw _exceptionFromResponse(response, "Cannot delete link", path);
231 } 232 }
232 return this; 233 return this;
233 }); 234 });
234 } 235 }
235 236
236 void _deleteSync({bool recursive: false}) { 237 void _deleteSync({bool recursive: false}) {
237 if (recursive) { 238 if (recursive) {
238 return new Directory(path).deleteSync(recursive: true); 239 return new Directory(path).deleteSync(recursive: true);
239 } 240 }
240 var result = _File._deleteLinkNative(path); 241 var result = _File._deleteLinkNative(_Namespace._namespace, path);
241 throwIfError(result, "Cannot delete link", path); 242 throwIfError(result, "Cannot delete link", path);
242 } 243 }
243 244
244 Future<Link> rename(String newPath) { 245 Future<Link> rename(String newPath) {
245 return _IOService 246 return _File
246 ._dispatch(_FILE_RENAME_LINK, [path, newPath]).then((response) { 247 ._dispatchWithNamespace(_FILE_RENAME_LINK, [null, path, newPath])
248 .then((response) {
247 if (_isErrorResponse(response)) { 249 if (_isErrorResponse(response)) {
248 throw _exceptionFromResponse( 250 throw _exceptionFromResponse(
249 response, "Cannot rename link to '$newPath'", path); 251 response, "Cannot rename link to '$newPath'", path);
250 } 252 }
251 return new Link(newPath); 253 return new Link(newPath);
252 }); 254 });
253 } 255 }
254 256
255 Link renameSync(String newPath) { 257 Link renameSync(String newPath) {
256 var result = _File._renameLink(path, newPath); 258 var result = _File._renameLink(_Namespace._namespace, path, newPath);
257 throwIfError(result, "Cannot rename link '$path' to '$newPath'"); 259 throwIfError(result, "Cannot rename link '$path' to '$newPath'");
258 return new Link(newPath); 260 return new Link(newPath);
259 } 261 }
260 262
261 Future<String> target() { 263 Future<String> target() {
262 return _IOService._dispatch(_FILE_LINK_TARGET, [path]).then((response) { 264 return _File._dispatchWithNamespace(_FILE_LINK_TARGET, [null, path])
265 .then((response) {
263 if (_isErrorResponse(response)) { 266 if (_isErrorResponse(response)) {
264 throw _exceptionFromResponse( 267 throw _exceptionFromResponse(
265 response, "Cannot get target of link", path); 268 response, "Cannot get target of link", path);
266 } 269 }
267 return response; 270 return response;
268 }); 271 });
269 } 272 }
270 273
271 String targetSync() { 274 String targetSync() {
272 var result = _File._linkTarget(path); 275 var result = _File._linkTarget(_Namespace._namespace, path);
273 throwIfError(result, "Cannot read link", path); 276 throwIfError(result, "Cannot read link", path);
274 return result; 277 return result;
275 } 278 }
276 279
277 static throwIfError(Object result, String msg, [String path = ""]) { 280 static throwIfError(Object result, String msg, [String path = ""]) {
278 if (result is OSError) { 281 if (result is OSError) {
279 throw new FileSystemException(msg, path, result); 282 throw new FileSystemException(msg, path, result);
280 } 283 }
281 } 284 }
282 285
283 bool _isErrorResponse(response) { 286 bool _isErrorResponse(response) {
284 return response is List && response[0] != _SUCCESS_RESPONSE; 287 return response is List && response[0] != _SUCCESS_RESPONSE;
285 } 288 }
286 289
287 _exceptionFromResponse(response, String message, String path) { 290 _exceptionFromResponse(response, String message, String path) {
288 assert(_isErrorResponse(response)); 291 assert(_isErrorResponse(response));
289 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { 292 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) {
290 case _ILLEGAL_ARGUMENT_RESPONSE: 293 case _ILLEGAL_ARGUMENT_RESPONSE:
291 return new ArgumentError(); 294 return new ArgumentError();
292 case _OSERROR_RESPONSE: 295 case _OSERROR_RESPONSE:
293 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], 296 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE],
294 response[_OSERROR_RESPONSE_ERROR_CODE]); 297 response[_OSERROR_RESPONSE_ERROR_CODE]);
295 return new FileSystemException(message, path, err); 298 return new FileSystemException(message, path, err);
296 default: 299 default:
297 return new Exception("Unknown error"); 300 return new Exception("Unknown error");
298 } 301 }
299 } 302 }
300 } 303 }
OLDNEW
« no previous file with comments | « sdk/lib/io/io_sources.gni ('k') | sdk/lib/io/namespace_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698