Work around issue 4928.

Review URL: https://codereview.chromium.org//13293006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20704 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
nweiz@google.com 2013-03-30 00:10:48 +00:00
parent 1049bd30dc
commit 16367f141e
2 changed files with 24 additions and 2 deletions

View file

@ -33,7 +33,7 @@ bool entryExists(String path) =>
/// Returns whether [link] exists on the file system. This will return `true`
/// for any symlink, regardless of what it points at or whether it's broken.
bool linkExists(String path) => new Link(path).existsSync();
bool linkExists(String link) => new Link(link).existsSync();
/// Returns whether [file] exists on the file system. This will return `true`
/// for a symlink only if that symlink is unbroken and points to a file.
@ -146,7 +146,15 @@ List<String> listDir(String dir, {bool recursive: false,
log.io("Listing directory $dir.");
var children = [];
for (var entity in new Directory(dir).listSync()) {
for (var entity in new Directory(dir).listSync(followLinks: false)) {
// TODO(nweiz): remove this when issue 4928 is fixed.
if (entity is Link) {
var link = entity.path;
// We treat broken symlinks as files, in that we don't want to recurse
// into them.
entity = dirExists(link) ? new Directory(link) : new File(link);
}
if (entity is File) {
var file = entity.path;
if (!includeHiddenFiles && path.basename(file).startsWith('.')) {

View file

@ -119,6 +119,20 @@ main() {
]));
}), completes);
});
test('treats a broken symlink as a file', () {
expect(withTempDir((temp) {
writeTextFile(path.join(temp, 'file1.txt'), '');
createDir(path.join(temp, 'dir'));
createSymlink(path.join(temp, 'dir'), path.join(temp, 'linkdir'));
deleteEntry(path.join(temp, 'dir'));
expect(listDir(temp, recursive: true), unorderedEquals([
path.join(temp, 'file1.txt'),
path.join(temp, 'linkdir')
]));
}), completes);
});
});
testExistencePredicate("entryExists", entryExists,