Skip to content

Commit

Permalink
don't warn on ignored directory symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
2ZeroSix committed Jan 18, 2022
1 parent ad3d5ac commit 25fd5bf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
11 changes: 6 additions & 5 deletions lib/src/validator/gitignore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ class GitignoreValidator extends Validator {
beneath: beneath,
listDir: (dir) {
var contents = Directory(resolve(dir)).listSync();
return contents
.where((e) => !(linkExists(e.path) && dirExists(e.path)))
.map((entity) => p.posix
.joinAll(p.split(p.relative(entity.path, from: root))));
return contents.map((entity) =>
p.posix.joinAll(p.split(p.relative(entity.path, from: root))));
},
ignoreForDir: (dir) {
final gitIgnore = resolve('$dir/.gitignore');
Expand All @@ -58,7 +56,10 @@ class GitignoreValidator extends Validator {
];
return rules.isEmpty ? null : Ignore(rules);
},
isDir: (dir) => dirExists(resolve(dir)),
isDir: (dir) {
final resolved = resolve(dir);
return dirExists(resolved) && !linkExists(resolved);
},
).map((file) {
final relative = p.relative(resolve(file), from: entrypoint.root.dir);
return Platform.isWindows
Expand Down
10 changes: 2 additions & 8 deletions test/package_list_files_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:test/test.dart';

import 'descriptor.dart' as d;
import 'test_pub.dart';
import 'validator/utils.dart';

late String root;
Entrypoint? entrypoint;
Expand Down Expand Up @@ -45,14 +46,7 @@ void main() {
]));
});

// On windows symlinks to directories are distinct from symlinks to files.
void createDirectorySymlink(String path, String target) {
if (Platform.isWindows) {
Process.runSync('cmd', ['/c', 'mklink', '/D', path, target]);
} else {
Link(path).createSync(target);
}
}


test('throws on directory symlinks', () async {
await d.dir(appPath, [
Expand Down
21 changes: 21 additions & 0 deletions test/validator/gitignore_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:test/test.dart';

import '../descriptor.dart' as d;
import '../test_pub.dart';
import 'utils.dart';

Future<void> expectValidation(
error,
Expand Down Expand Up @@ -102,4 +103,24 @@ void main() {
await expectValidation(contains('Package has 0 warnings.'), 0,
workingDirectory: packageRoot);
});

test('Should consider symlinks to be valid files and not list them as gitignored', () async {
final git = d.git(appPath, [
...d.validPackage.contents,
d.dir('dir_with_symlink', [
d.file('.pubignore', '/symlink'),
]),
]);
await git.create();
final packageRoot = p.join(d.sandbox, appPath);
await pubGet(
environment: {'_PUB_TEST_SDK_VERSION': '1.12.0'},
workingDirectory: packageRoot);
createDirectorySymlink(
p.join(d.sandbox, appPath, 'dir_with_symlink', 'symlink'), '..');
git.commit();

await expectValidation(contains('Package has 0 warnings.'), 0,
workingDirectory: packageRoot);
});
}
11 changes: 11 additions & 0 deletions test/validator/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:test/test.dart';

import '../test_pub.dart';
Expand All @@ -16,3 +18,12 @@ Future<void> expectValidation(ValidatorCreator fn,
expect(validator.warnings, warnings ?? isEmpty);
expect(validator.hints, hints ?? isEmpty);
}

// On windows symlinks to directories are distinct from symlinks to files.
void createDirectorySymlink(String path, String target) {
if (Platform.isWindows) {
Process.runSync('cmd', ['/c', 'mklink', '/D', path, target]);
} else {
Link(path).createSync(target);
}
}

0 comments on commit 25fd5bf

Please sign in to comment.