From 700943631a84a88270a99f3baf6dcb2843c584d1 Mon Sep 17 00:00:00 2001 From: Gabriel Terwesten Date: Sat, 23 Apr 2022 11:23:24 +0200 Subject: [PATCH] fix: handle unresolvable symbolic links (#280) Fixes #269 --- packages/melos/lib/src/common/utils.dart | 17 ++++++++++++++++- packages/melos/test/workspace_test.dart | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/melos/lib/src/common/utils.dart b/packages/melos/lib/src/common/utils.dart index 8edf1c80..042d7acd 100644 --- a/packages/melos/lib/src/common/utils.dart +++ b/packages/melos/lib/src/common/utils.dart @@ -407,7 +407,7 @@ extension DirectoryUtils on Directory { } } else if (entity is Link) { if (!followLinks || - visitedLinks.contains(await entity.resolveSymbolicLinks())) { + visitedLinks.contains(await entity.tryResolveSymbolicLinks())) { yield entity; break; } @@ -440,6 +440,21 @@ extension DirectoryUtils on Directory { } } +extension FileSystemEntityUtils on FileSystemEntity { + /// Tries to resolve the path of this [FileSystemEntity] through + /// [resolveSymbolicLinks] and returns `null` if the path cannot be resolved. + /// + /// For example, a path cannot be resolved when it is a link to a non-existing + /// file. + Future tryResolveSymbolicLinks() async { + try { + return await resolveSymbolicLinks(); + } on FileSystemException { + return null; + } + } +} + extension StreamUtils on Stream { /// Runs [convert] for each event in this stream and emits the result, while /// ensuring that no more events than specified by [parallelism] are being diff --git a/packages/melos/test/workspace_test.dart b/packages/melos/test/workspace_test.dart index cceb8014..6f19c867 100644 --- a/packages/melos/test/workspace_test.dart +++ b/packages/melos/test/workspace_test.dart @@ -20,6 +20,7 @@ import 'package:melos/src/common/glob.dart'; import 'package:melos/src/package.dart'; import 'package:melos/src/workspace.dart'; import 'package:melos/src/workspace_configs.dart'; +import 'package:path/path.dart' as p; import 'package:pubspec/pubspec.dart'; import 'package:test/test.dart'; @@ -135,6 +136,19 @@ The packages that caused the problem are: }), ); + test('load workspace config when workspace contains broken symlink', + () async { + final workspaceDir = createTemporaryWorkspaceDirectory(); + + final link = Link(p.join(workspaceDir.path, 'link')); + await link.create(p.join(workspaceDir.path, 'does-not-exist')); + + await MelosWorkspace.fromConfig( + await MelosWorkspaceConfig.fromDirectory(workspaceDir), + logger: TestLogger(), + ); + }); + group('package filtering', () { group('--include-dependencies', () { test(