| 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 io; | 6 library io; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 var relative = path.relative(entry, from: dir); | 26 var relative = path.relative(entry, from: dir); |
| 27 return !path.isAbsolute(relative) && path.split(relative)[0] != '..'; | 27 return !path.isAbsolute(relative) && path.split(relative)[0] != '..'; |
| 28 } | 28 } |
| 29 | 29 |
| 30 /// Determines if a file or directory exists at [path]. | 30 /// Determines if a file or directory exists at [path]. |
| 31 bool entryExists(String path) => | 31 bool entryExists(String path) => |
| 32 dirExists(path) || fileExists(path) || linkExists(path); | 32 dirExists(path) || fileExists(path) || linkExists(path); |
| 33 | 33 |
| 34 /// Returns whether [link] exists on the file system. This will return `true` | 34 /// Returns whether [link] exists on the file system. This will return `true` |
| 35 /// for any symlink, regardless of what it points at or whether it's broken. | 35 /// for any symlink, regardless of what it points at or whether it's broken. |
| 36 bool linkExists(String path) => new Link(path).existsSync(); | 36 bool linkExists(String link) => new Link(link).existsSync(); |
| 37 | 37 |
| 38 /// Returns whether [file] exists on the file system. This will return `true` | 38 /// Returns whether [file] exists on the file system. This will return `true` |
| 39 /// for a symlink only if that symlink is unbroken and points to a file. | 39 /// for a symlink only if that symlink is unbroken and points to a file. |
| 40 bool fileExists(String file) => new File(file).existsSync(); | 40 bool fileExists(String file) => new File(file).existsSync(); |
| 41 | 41 |
| 42 /// Reads the contents of the text file [file]. | 42 /// Reads the contents of the text file [file]. |
| 43 String readTextFile(String file) => | 43 String readTextFile(String file) => |
| 44 new File(file).readAsStringSync(encoding: Encoding.UTF_8); | 44 new File(file).readAsStringSync(encoding: Encoding.UTF_8); |
| 45 | 45 |
| 46 /// Reads the contents of the binary file [file]. | 46 /// Reads the contents of the binary file [file]. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // Avoid recursive symlinks. | 139 // Avoid recursive symlinks. |
| 140 var resolvedPath = new File(dir).fullPathSync(); | 140 var resolvedPath = new File(dir).fullPathSync(); |
| 141 if (listedDirectories.contains(resolvedPath)) return []; | 141 if (listedDirectories.contains(resolvedPath)) return []; |
| 142 | 142 |
| 143 listedDirectories = new Set<String>.from(listedDirectories); | 143 listedDirectories = new Set<String>.from(listedDirectories); |
| 144 listedDirectories.add(resolvedPath); | 144 listedDirectories.add(resolvedPath); |
| 145 | 145 |
| 146 log.io("Listing directory $dir."); | 146 log.io("Listing directory $dir."); |
| 147 | 147 |
| 148 var children = []; | 148 var children = []; |
| 149 for (var entity in new Directory(dir).listSync()) { | 149 for (var entity in new Directory(dir).listSync(followLinks: false)) { |
| 150 // TODO(nweiz): remove this when issue 4928 is fixed. |
| 151 if (entity is Link) { |
| 152 var link = entity.path; |
| 153 // We treat broken symlinks as files, in that we don't want to recurse |
| 154 // into them. |
| 155 entity = dirExists(link) ? new Directory(link) : new File(link); |
| 156 } |
| 157 |
| 150 if (entity is File) { | 158 if (entity is File) { |
| 151 var file = entity.path; | 159 var file = entity.path; |
| 152 if (!includeHiddenFiles && path.basename(file).startsWith('.')) { | 160 if (!includeHiddenFiles && path.basename(file).startsWith('.')) { |
| 153 continue; | 161 continue; |
| 154 } | 162 } |
| 155 contents.add(file); | 163 contents.add(file); |
| 156 } else if (entity is Directory) { | 164 } else if (entity is Directory) { |
| 157 var file = entity.path; | 165 var file = entity.path; |
| 158 if (!includeHiddenFiles && path.basename(file).startsWith('.')) { | 166 if (!includeHiddenFiles && path.basename(file).startsWith('.')) { |
| 159 continue; | 167 continue; |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 739 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
| 732 | 740 |
| 733 bool get success => exitCode == 0; | 741 bool get success => exitCode == 0; |
| 734 } | 742 } |
| 735 | 743 |
| 736 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 744 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 737 Uri _getUri(uri) { | 745 Uri _getUri(uri) { |
| 738 if (uri is Uri) return uri; | 746 if (uri is Uri) return uri; |
| 739 return Uri.parse(uri); | 747 return Uri.parse(uri); |
| 740 } | 748 } |
| OLD | NEW |