| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 void copyFile(String source, String destination) { | 211 void copyFile(String source, String destination) { |
| 212 writeBinaryFile(destination, readBinaryFile(source)); | 212 writeBinaryFile(destination, readBinaryFile(source)); |
| 213 } | 213 } |
| 214 | 214 |
| 215 /// Creates a directory [dir]. | 215 /// Creates a directory [dir]. |
| 216 String createDir(String dir) { | 216 String createDir(String dir) { |
| 217 new Directory(dir).createSync(); | 217 new Directory(dir).createSync(); |
| 218 return dir; | 218 return dir; |
| 219 } | 219 } |
| 220 | 220 |
| 221 /// Ensures that [dirPath] and all its parent directories exist. If they don't | 221 /// Ensures that [dir] and all its parent directories exist. If they don't |
| 222 /// exist, creates them. | 222 /// exist, creates them. |
| 223 String ensureDir(String dirPath) { | 223 String ensureDir(String dir) { |
| 224 log.fine("Ensuring directory $dirPath exists."); | 224 new Directory(dir).createSync(recursive: true); |
| 225 var dir = new Directory(dirPath); | 225 return dir; |
| 226 if (dirPath == '.' || dirExists(dirPath)) return dirPath; | |
| 227 | |
| 228 ensureDir(path.dirname(dirPath)); | |
| 229 | |
| 230 try { | |
| 231 createDir(dirPath); | |
| 232 } on FileSystemException catch (ex) { | |
| 233 // Error 17 means the directory already exists (or 183 on Windows). | |
| 234 if (ex.osError.errorCode == 17 || ex.osError.errorCode == 183) { | |
| 235 log.fine("Got 'already exists' error when creating directory."); | |
| 236 } else { | |
| 237 throw ex; | |
| 238 } | |
| 239 } | |
| 240 | |
| 241 return dirPath; | |
| 242 } | 226 } |
| 243 | 227 |
| 244 /// Creates a temp directory in [dir], whose name will be [prefix] with | 228 /// Creates a temp directory in [dir], whose name will be [prefix] with |
| 245 /// characters appended to it to make a unique name. | 229 /// characters appended to it to make a unique name. |
| 246 /// Returns the path of the created directory. | 230 /// Returns the path of the created directory. |
| 247 String createTempDir(String base, String prefix) { | 231 String createTempDir(String base, String prefix) { |
| 248 var tempDir = new Directory(base).createTempSync(prefix); | 232 var tempDir = new Directory(base).createTempSync(prefix); |
| 249 log.io("Created temp directory ${tempDir.path}"); | 233 log.io("Created temp directory ${tempDir.path}"); |
| 250 return tempDir.path; | 234 return tempDir.path; |
| 251 } | 235 } |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 824 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
| 841 | 825 |
| 842 bool get success => exitCode == 0; | 826 bool get success => exitCode == 0; |
| 843 } | 827 } |
| 844 | 828 |
| 845 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 829 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 846 Uri _getUri(uri) { | 830 Uri _getUri(uri) { |
| 847 if (uri is Uri) return uri; | 831 if (uri is Uri) return uri; |
| 848 return Uri.parse(uri); | 832 return Uri.parse(uri); |
| 849 } | 833 } |
| OLD | NEW |