Skip to content

Commit 7679721

Browse files
committed
Detect cycles
1 parent f620e18 commit 7679721

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/src/package.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,35 @@ See $workspacesDocUrl for more information.
294294
}
295295
}
296296

297+
/// We check each directory that it doesn't symlink-resolve to the
298+
/// symlink-resolution of any parent directory of itself. This avoids
299+
/// cycles.
300+
///
301+
/// Cache the symlink resolutions here.
302+
final symlinkResolvedDirs = <String, String>{};
303+
297304
final result = Ignore.listFiles(
298305
beneath: beneath,
299306
listDir: (dir) {
300-
final resolvedDir = resolve(dir);
307+
final resolvedDir = p.normalize(resolve(dir));
301308
verifyLink(resolvedDir);
309+
310+
{
311+
final symlinkResolvedDir = symlinkResolvedDirs[resolvedDir] ??=
312+
Directory(resolvedDir).resolveSymbolicLinksSync();
313+
314+
for (final parent in parentDirs(p.dirname(resolvedDir))) {
315+
final symlinkResolvedParent = symlinkResolvedDirs[parent] ??=
316+
Directory(parent).resolveSymbolicLinksSync();
317+
if (p.equals(symlinkResolvedDir, symlinkResolvedParent)) {
318+
dataError('''
319+
Pub does not support symlink cycles.
320+
321+
$resolvedDir => ${p.canonicalize(parent)}
322+
''');
323+
}
324+
}
325+
}
302326
var contents = Directory(resolvedDir).listSync(followLinks: false);
303327

304328
if (!recursive) {

test/package_list_files_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void main() {
150150
(e) => e.message,
151151
'message',
152152
contains(
153-
'Could not resolve symbolic link',
153+
'Pub does not support symlink cycles.',
154154
),
155155
),
156156
),
@@ -221,7 +221,7 @@ void main() {
221221
isA<DataException>().having(
222222
(e) => e.message,
223223
'message',
224-
contains('Could not resolve symbolic link'),
224+
contains('Pub does not support symlink cycles.'),
225225
),
226226
),
227227
);

0 commit comments

Comments
 (0)