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

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

Issue 17638007: Create LinkExceptions using the right arguments, in dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added test Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/io/link_test.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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 139 }
140 return this; 140 return this;
141 }); 141 });
142 } 142 }
143 143
144 void createSync(String target) { 144 void createSync(String target) {
145 if (Platform.operatingSystem == 'windows') { 145 if (Platform.operatingSystem == 'windows') {
146 target = _makeWindowsLinkTarget(target); 146 target = _makeWindowsLinkTarget(target);
147 } 147 }
148 var result = _File._createLink(path, target); 148 var result = _File._createLink(path, target);
149 throwIfError(result, "Cannot create link '$path'"); 149 throwIfError(result, "Cannot create link", path);
150 } 150 }
151 151
152 // Put target into the form "\??\C:\my\target\dir". 152 // Put target into the form "\??\C:\my\target\dir".
153 String _makeWindowsLinkTarget(String target) { 153 String _makeWindowsLinkTarget(String target) {
154 if (target.startsWith('\\??\\')) { 154 if (target.startsWith('\\??\\')) {
155 return target; 155 return target;
156 } 156 }
157 if (!(target.length > 3 && target[1] == ':' && target[2] == '\\')) { 157 if (!(target.length > 3 && target[1] == ':' && target[2] == '\\')) {
158 target = new File(target).fullPathSync(); 158 target = new File(target).fullPathSync();
159 } 159 }
(...skipping 21 matching lines...) Expand all
181 return _fileService.call(request).then((response) { 181 return _fileService.call(request).then((response) {
182 if (_isErrorResponse(response)) { 182 if (_isErrorResponse(response)) {
183 throw _exceptionFromResponse(response, "Cannot delete link '$path'"); 183 throw _exceptionFromResponse(response, "Cannot delete link '$path'");
184 } 184 }
185 return this; 185 return this;
186 }); 186 });
187 } 187 }
188 188
189 void deleteSync() { 189 void deleteSync() {
190 var result = _File._deleteLink(path); 190 var result = _File._deleteLink(path);
191 throwIfError(result, "Cannot delete link '$path'"); 191 throwIfError(result, "Cannot delete link", path);
192 } 192 }
193 193
194 Future<String> target() { 194 Future<String> target() {
195 _ensureFileService(); 195 _ensureFileService();
196 List request = new List(2); 196 List request = new List(2);
197 request[0] = _LINK_TARGET_REQUEST; 197 request[0] = _LINK_TARGET_REQUEST;
198 request[1] = path; 198 request[1] = path;
199 return _fileService.call(request).then((response) { 199 return _fileService.call(request).then((response) {
200 if (_isErrorResponse(response)) { 200 if (_isErrorResponse(response)) {
201 throw _exceptionFromResponse(response, 201 throw _exceptionFromResponse(response,
202 "Cannot get target of link '$path'"); 202 "Cannot get target of link '$path'");
203 } 203 }
204 return response; 204 return response;
205 }); 205 });
206 } 206 }
207 207
208 String targetSync() { 208 String targetSync() {
209 var result = _File._linkTarget(path); 209 var result = _File._linkTarget(path);
210 throwIfError(result, "Cannot read link '$path'"); 210 throwIfError(result, "Cannot read link", path);
211 return result; 211 return result;
212 } 212 }
213 213
214 static throwIfError(Object result, String msg) { 214 static throwIfError(Object result, String msg, [String path = ""]) {
215 if (result is OSError) { 215 if (result is OSError) {
216 throw new LinkException(msg, result); 216 throw new LinkException(msg, path, result);
217 } 217 }
218 } 218 }
219 219
220 bool _isErrorResponse(response) { 220 bool _isErrorResponse(response) {
221 return response is List && response[0] != _SUCCESS_RESPONSE; 221 return response is List && response[0] != _SUCCESS_RESPONSE;
222 } 222 }
223 223
224 void _ensureFileService() { 224 void _ensureFileService() {
225 if (_fileService == null) { 225 if (_fileService == null) {
226 _fileService = _FileUtils._newServicePort(); 226 _fileService = _FileUtils._newServicePort();
(...skipping 11 matching lines...) Expand all
238 return new LinkException(message, err); 238 return new LinkException(message, err);
239 default: 239 default:
240 return new Exception("Unknown error"); 240 return new Exception("Unknown error");
241 } 241 }
242 } 242 }
243 } 243 }
244 244
245 245
246 class LinkException implements IOException { 246 class LinkException implements IOException {
247 const LinkException([String this.message = "", 247 const LinkException([String this.message = "",
248 String this.path = "", 248 String this.path = "",
249 OSError this.osError = null]); 249 OSError this.osError = null]);
250 String toString() { 250 String toString() {
251 StringBuffer sb = new StringBuffer(); 251 StringBuffer sb = new StringBuffer();
252 sb.write("LinkException"); 252 sb.write("LinkException");
253 if (!message.isEmpty) { 253 if (!message.isEmpty) {
254 sb.write(": $message"); 254 sb.write(": $message");
255 if (path != null) { 255 if (path != null) {
256 sb.write(", path = $path"); 256 sb.write(", path = $path");
257 } 257 }
258 if (osError != null) { 258 if (osError != null) {
259 sb.write(" ($osError)"); 259 sb.write(" ($osError)");
260 } 260 }
261 } else if (osError != null) { 261 } else if (osError != null) {
262 sb.write(": $osError"); 262 sb.write(": $osError");
263 if (path != null) { 263 if (path != null) {
264 sb.write(", path = $path"); 264 sb.write(", path = $path");
265 } 265 }
266 } 266 }
267 return sb.toString(); 267 return sb.toString();
268 } 268 }
269 final String message; 269 final String message;
270 final String path; 270 final String path;
271 final OSError osError; 271 final OSError osError;
272 } 272 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/link_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698