Skip to content

Commit

Permalink
Don't crash on directory symlinks (default behavior is copy-paste of …
Browse files Browse the repository at this point in the history
…symlinked directories in published archive)
  • Loading branch information
2ZeroSix committed Jan 18, 2022
1 parent 25fd5bf commit 163d23c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/src/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,6 @@ class Package {
contents = contents.where((entity) => entity is! Directory).toList();
}
return contents.map((entity) {
if (linkExists(entity.path)) {
final target = Link(entity.path).targetSync();
if (dirExists(entity.path)) {
throw DataException(
'''Pub does not support publishing packages with directory symlinks: `${entity.path}`.''');
}
if (!fileExists(entity.path)) {
throw DataException(
'''Pub does not support publishing packages with non-resolving symlink: `${entity.path}` => `$target`.''');
}
}
final relative = p.relative(entity.path, from: root);
if (Platform.isWindows) {
return p.posix.joinAll(p.split(relative));
Expand Down Expand Up @@ -323,7 +312,16 @@ class Package {
);
},
isDir: (dir) => dirExists(resolve(dir)),
).map(resolve).toList();
).map(resolve).map((path) {
if (linkExists(path)) {
final target = Link(path).targetSync();
if (!fileExists(path)) {
throw DataException(
'''Pub does not support publishing packages with non-resolving symlink: `${path}` => `$target`.''');
}
}
return path;
}).toList();
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/package_list_files_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ void main() {
);
});

test('not throws on ignored directory symlinks', () async {
await d.dir(appPath, [
d.pubspec({'name': 'myapp'}),
d.file('file1.txt', 'contents'),
d.file('file2.txt', 'contents'),
d.dir('subdir', [
d.file('.pubignore', 'symlink'),
d.dir('a', [d.file('file')]),
]),
]).create();
createDirectorySymlink(
p.join(d.sandbox, appPath, 'subdir', 'symlink'), 'a');

createEntrypoint();

expect(entrypoint!.root.listFiles(), {
p.join(root, 'pubspec.yaml'),
p.join(root, 'file1.txt'),
p.join(root, 'file2.txt'),
p.join(root, 'subdir', 'a', 'file'),
});
});

test('can list a package inside a symlinked folder', () async {
await d.dir(appPath, [
d.pubspec({'name': 'myapp'}),
Expand Down

0 comments on commit 163d23c

Please sign in to comment.