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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
6 library pub.io; | 6 library pub.io; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:collection'; | 9 import 'dart:collection'; |
10 import 'dart:convert'; | 10 import 'dart:convert'; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 if (ex.osError.errorCode == 17 || ex.osError.errorCode == 183) { | 221 if (ex.osError.errorCode == 17 || ex.osError.errorCode == 183) { |
222 log.fine("Got 'already exists' error when creating directory."); | 222 log.fine("Got 'already exists' error when creating directory."); |
223 } else { | 223 } else { |
224 throw ex; | 224 throw ex; |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 return dirPath; | 228 return dirPath; |
229 } | 229 } |
230 | 230 |
231 /// Creates a temp directory whose name will be based on [dir] with a unique | 231 /// Creates a temp directory in [dir], whose name will be [prefix] with |
232 /// suffix appended to it. If [dir] is not provided, a temp directory will be | 232 /// characters appended to it to make a unique name. |
233 /// created in a platform-dependent temporary location. Returns the path of the | 233 /// Returns the path of the created directory. |
234 /// created directory. | |
235 String createTempDir(String base, String prefix) { | 234 String createTempDir(String base, String prefix) { |
236 var tempDir = new Directory(base).createTempSync(prefix); | 235 var tempDir = new Directory(base).createTempSync(prefix); |
237 log.io("Created temp directory ${tempDir.path}"); | 236 log.io("Created temp directory ${tempDir.path}"); |
238 return tempDir.path; | 237 return tempDir.path; |
239 } | 238 } |
240 | 239 |
| 240 /// Creates a temp directory in the system temp directory, whose name will be |
| 241 /// 'pub_' with characters appended to it to make a unique name. |
| 242 /// Returns the path of the created directory. |
241 String createSystemTempDir() { | 243 String createSystemTempDir() { |
242 var tempDir = Directory.createSystemTempSync('pub_'); | 244 var tempDir = Directory.systemTemp.createTempSync('pub_'); |
243 log.io("Created temp directory ${tempDir.path}"); | 245 log.io("Created temp directory ${tempDir.path}"); |
244 return tempDir.path; | 246 return tempDir.path; |
245 } | 247 } |
246 | 248 |
247 | |
248 /// Lists the contents of [dir]. If [recursive] is `true`, lists subdirectory | 249 /// Lists the contents of [dir]. If [recursive] is `true`, lists subdirectory |
249 /// contents (defaults to `false`). If [includeHidden] is `true`, includes files | 250 /// contents (defaults to `false`). If [includeHidden] is `true`, includes files |
250 /// and directories beginning with `.` (defaults to `false`). | 251 /// and directories beginning with `.` (defaults to `false`). |
251 /// | 252 /// |
252 /// The returned paths are guaranteed to begin with [dir]. | 253 /// The returned paths are guaranteed to begin with [dir]. |
253 List<String> listDir(String dir, {bool recursive: false, | 254 List<String> listDir(String dir, {bool recursive: false, |
254 bool includeHidden: false}) { | 255 bool includeHidden: false}) { |
255 List<String> doList(String dir, Set<String> listedDirectories) { | 256 List<String> doList(String dir, Set<String> listedDirectories) { |
256 var contents = <String>[]; | 257 var contents = <String>[]; |
257 | 258 |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 833 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
833 | 834 |
834 bool get success => exitCode == 0; | 835 bool get success => exitCode == 0; |
835 } | 836 } |
836 | 837 |
837 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 838 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
838 Uri _getUri(uri) { | 839 Uri _getUri(uri) { |
839 if (uri is Uri) return uri; | 840 if (uri is Uri) return uri; |
840 return Uri.parse(uri); | 841 return Uri.parse(uri); |
841 } | 842 } |
OLD | NEW |