OLD | NEW |
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return target; | 157 return target; |
158 } | 158 } |
159 | 159 |
160 void updateSync(String target, {bool linkRelative: false }) { | 160 void updateSync(String target, {bool linkRelative: false }) { |
161 // TODO(whesse): Replace with atomic update, where supported by platform. | 161 // TODO(whesse): Replace with atomic update, where supported by platform. |
162 deleteSync(); | 162 deleteSync(); |
163 createSync(target); | 163 createSync(target); |
164 } | 164 } |
165 | 165 |
166 Future<Link> delete() { | 166 Future<Link> delete() { |
167 return new File(path).delete().then((_) => this); | 167 _ensureFileService(); |
| 168 List request = new List(2); |
| 169 request[0] = _LINK_DELETE_REQUEST; |
| 170 request[1] = path; |
| 171 return _fileService.call(request).then((response) { |
| 172 if (_isErrorResponse(response)) { |
| 173 throw _exceptionFromResponse(response, "Cannot delete file '$path'"); |
| 174 } |
| 175 return this; |
| 176 }); |
168 } | 177 } |
169 | 178 |
170 void deleteSync() { | 179 void deleteSync() { |
171 new File(path).deleteSync(); | 180 var result = _File._deleteLink(path); |
| 181 throwIfError(result, "Cannot delete file '$path'"); |
172 } | 182 } |
173 | 183 |
174 Future<String> target() { | 184 Future<String> target() { |
175 // TODO(whesse): Replace with asynchronous version. | 185 // TODO(whesse): Replace with asynchronous version. |
176 return new Future.of(targetSync); | 186 return new Future.of(targetSync); |
177 } | 187 } |
178 | 188 |
179 String targetSync() { | 189 String targetSync() { |
180 var result = _File._linkTarget(path); | 190 var result = _File._linkTarget(path); |
181 if (result is OSError) { | 191 if (result is OSError) { |
182 throw new LinkIOException("Error in Link.targetSync", result); | 192 throw new LinkIOException("Error in Link.targetSync", result); |
183 } | 193 } |
184 return result; | 194 return result; |
185 } | 195 } |
| 196 |
| 197 static throwIfError(Object result, String msg) { |
| 198 if (result is OSError) { |
| 199 throw new FileIOException(msg, result); |
| 200 } |
| 201 } |
186 } | 202 } |
187 | 203 |
188 | 204 |
189 class LinkIOException implements Exception { | 205 class LinkIOException implements Exception { |
190 const LinkIOException([String this.message = "", | 206 const LinkIOException([String this.message = "", |
191 String this.path = "", | 207 String this.path = "", |
192 OSError this.osError = null]); | 208 OSError this.osError = null]); |
193 String toString() { | 209 String toString() { |
194 StringBuffer sb = new StringBuffer(); | 210 StringBuffer sb = new StringBuffer(); |
195 sb.write("LinkIOException"); | 211 sb.write("LinkIOException"); |
(...skipping 10 matching lines...) Expand all Loading... |
206 if (path != null) { | 222 if (path != null) { |
207 sb.write(", path = $path"); | 223 sb.write(", path = $path"); |
208 } | 224 } |
209 } | 225 } |
210 return sb.toString(); | 226 return sb.toString(); |
211 } | 227 } |
212 final String message; | 228 final String message; |
213 final String path; | 229 final String path; |
214 final OSError osError; | 230 final OSError osError; |
215 } | 231 } |
OLD | NEW |