| 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 library utils; | 5 library utils; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analyzer_experimental/analyzer.dart'; | 9 import 'package:analyzer_experimental/analyzer.dart'; |
| 10 import 'package:path/path.dart' as pathos; | 10 import 'package:path/path.dart' as pathos; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 return null; | 32 return null; |
| 33 }); | 33 }); |
| 34 } | 34 } |
| 35 | 35 |
| 36 /// Creates a temporary directory and passes its path to [fn]. Once [fn] | 36 /// Creates a temporary directory and passes its path to [fn]. Once [fn] |
| 37 /// completes, the temporary directory and all its contents will be deleted. | 37 /// completes, the temporary directory and all its contents will be deleted. |
| 38 /// | 38 /// |
| 39 /// Returns the return value of [fn]. | 39 /// Returns the return value of [fn]. |
| 40 dynamic withTempDir(fn(String path)) { | 40 dynamic withTempDir(fn(String path)) { |
| 41 var tempDir = new Directory('').createTempSync().path; | 41 var tempDir = |
| 42 Directory.systemTemp.createTempSync('analyzer_experimental_').path; |
| 42 try { | 43 try { |
| 43 return fn(tempDir); | 44 return fn(tempDir); |
| 44 } finally { | 45 } finally { |
| 45 new Directory(tempDir).deleteSync(recursive: true); | 46 new Directory(tempDir).deleteSync(recursive: true); |
| 46 } | 47 } |
| 47 } | 48 } |
| OLD | NEW |