-
Notifications
You must be signed in to change notification settings - Fork 232
fix: symlinks handling #3298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix: symlinks handling #3298
Changes from 56 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
0189750
don't warn on ignored directory symlinks
2ZeroSix 7320081
Don't crash on directory symlinks (default behavior is copy-paste of …
2ZeroSix 963b645
add missing await
2ZeroSix b87e533
remove unnecessary brackets in string interpolation
2ZeroSix c087295
codestyle
2ZeroSix 6e23dcc
add symlink cycle test
2ZeroSix b9b9314
use ignore rule without delimiter in checked-in but ignored warning test
2ZeroSix 4486f00
probable fix for cycles on windows
2ZeroSix e49c45b
don't follow links
2ZeroSix 7e1cb20
use appropriate error message (wrongly cherry-picked)
2ZeroSix 05f6cd9
double check for directory symlinks
2ZeroSix 0a6ffaa
replace "throws" => "not throws on valid directory symlinks"
2ZeroSix 10b8e3e
Revert "double check for directory symlinks"
2ZeroSix f6bd8d2
Revert "don't follow links"
2ZeroSix bfc30e5
Revert "probable fix for cycles on windows"
2ZeroSix b1b69bc
try to resolve symbolic link manually before listSync invocation
2ZeroSix d97bfe2
Revert "Revert "probable fix for cycles on windows""
2ZeroSix add6e5c
Revert "Revert "don't follow links""
2ZeroSix 380a1e0
Revert "Revert "double check for directory symlinks""
2ZeroSix 6623ea2
add additional cycles tests
2ZeroSix 8e6aa02
try to see detailed log on windows
2ZeroSix aa391dc
maintain list of visited symlink dirs
2ZeroSix dfb47e5
use resolvedLinkTargets
2ZeroSix 2705410
fix assertLinksResolvable
2ZeroSix f3aa7c3
update message
2ZeroSix ad092c5
add a bit more tests
2ZeroSix 003a59d
try to resolve or else count occurrences
2ZeroSix 73455c6
typo: symlinks => symlink
2ZeroSix fa09a85
rewrite symlinks detection
2ZeroSix 1a72dc3
create and append in single assertion
2ZeroSix 3a58e92
posix dirname for internal representation
2ZeroSix ce5544a
fix copy on write solution
2ZeroSix d5b595b
code style
2ZeroSix 7745fc7
explicitly say that error happened because of loop
2ZeroSix af93eb1
not throws on ignored broken directory symlinks
2ZeroSix 8aa575d
not throws on valid links to the same directory
2ZeroSix 9700d92
instant loop is actually non-resolving
2ZeroSix 0dcf557
add detailed comment with explanation
2ZeroSix 9c2c78d
make assert methods static
2ZeroSix 42b0821
add test for nested loop
2ZeroSix 020f465
rename: posixDir => internalDir
2ZeroSix 07b8cf9
make assertions private
2ZeroSix 68831dc
use join instead of raw posix path
2ZeroSix cdb66d3
Use FileSystemEntity.resolveSymbolicLinks
sigurdm f98d77d
Merge
sigurdm 599a42f
publish integration test
sigurdm 4ed382a
Rely on system detecting cycles
sigurdm 0c56b15
fmt
sigurdm f620e18
Remove deprecated lint
sigurdm 7679721
Detect cycles
sigurdm f8ee397
canonicalize before examining parents (gets rid of /.)
sigurdm 6d2ef92
Update test/package_list_files_test.dart
sigurdm 3bd1765
Address review comments
sigurdm 3837226
Merge remote-tracking branch '2ZeroSix/fix/symlinks' into fix/symlinks
sigurdm 66b1ae3
Add missing file
sigurdm d4a89e0
attempt at windows fix
sigurdm 8909acf
Use link descriptors and prefix in lish/symlinks_test
sigurdm 778e35c
Move link() -> descriptor.dart
sigurdm b179ccf
move test/link_descriptor.dart -> test/descriptor/linkdescriptor.dart
sigurdm 2d8ec9b
attempt at windows fix2
sigurdm ecbeef1
One more use of d.link
sigurdm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sigurdm marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// 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:path/path.dart' as p; | ||
import 'package:test/test.dart'; | ||
|
||
import 'descriptor.dart' as d; | ||
|
||
/// Describes a symlink. | ||
class LinkDescriptor extends d.Descriptor { | ||
/// On windows symlinks to directories are distinct from symlinks to files. | ||
final bool forceDirectory; | ||
final String target; | ||
LinkDescriptor(super.name, this.target, {this.forceDirectory = false}); | ||
|
||
@override | ||
Future<void> create([String? parent]) async { | ||
final path = p.join(parent ?? d.sandbox, name); | ||
if (forceDirectory) { | ||
if (Platform.isWindows) { | ||
Process.runSync('cmd', ['/c', 'mklink', '/D', path, target]); | ||
} else { | ||
Link(path).createSync(target); | ||
} | ||
} else { | ||
Link(path).createSync(target); | ||
} | ||
} | ||
|
||
@override | ||
String describe() { | ||
return 'symlink at $name targeting $target'; | ||
} | ||
|
||
@override | ||
Future<void> validate([String? parent]) async { | ||
final link = Link(p.join(parent ?? d.sandbox, name)); | ||
try { | ||
final actualTarget = link.targetSync(); | ||
expect( | ||
actualTarget, | ||
target, | ||
reason: 'Link doesn\'t point where expected.', | ||
); | ||
} on FileSystemException catch (e) { | ||
fail('Could not read link at $name $e'); | ||
} | ||
} | ||
} | ||
|
||
d.Descriptor link(String name, String target, {bool forceDirectory = false}) { | ||
return LinkDescriptor(name, target, forceDirectory: forceDirectory); | ||
} | ||
sigurdm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// 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:path/path.dart' as p; | ||
import 'package:tar/tar.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../descriptor.dart'; | ||
sigurdm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
import '../test_pub.dart'; | ||
|
||
Future<void> main() async { | ||
test('symlink directories are replaced by their targets', () async { | ||
await validPackage().create(); | ||
await dir('a', [file('aa', 'aaa')]).create(); | ||
await file('t', 'ttt').create(); | ||
|
||
await dir(appPath, [ | ||
dir('b', [file('bb', 'bbb')]), | ||
]).create(); | ||
Link(p.join(sandbox, appPath, 'symlink_to_dir_outside_package')) | ||
.createSync(p.join(sandbox, 'a')); | ||
sigurdm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Link(p.join(sandbox, appPath, 'symlink_to_dir_outside_package_relative')) | ||
.createSync(p.join('..', 'a')); | ||
Link(p.join(sandbox, appPath, 'symlink_to_dir_inside_package')) | ||
.createSync(p.join(sandbox, appPath, 'b')); | ||
Link(p.join(sandbox, appPath, 'symlink_to_dir_inside_package_relative')) | ||
.createSync('b'); | ||
Link(p.join(sandbox, appPath, 'b', 'l')).createSync(p.join(sandbox, 't')); | ||
sigurdm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
await runPub(args: ['publish', '--to-archive=archive.tar.gz']); | ||
|
||
final reader = TarReader( | ||
File(p.join(sandbox, appPath, 'archive.tar.gz')) | ||
.openRead() | ||
.transform(GZipCodec().decoder), | ||
); | ||
|
||
while (await reader.moveNext()) { | ||
final current = reader.current; | ||
expect(current.type, isNot(TypeFlag.symlink)); | ||
} | ||
|
||
await runPub(args: ['cache', 'preload', 'archive.tar.gz']); | ||
|
||
await dir('test_pkg-1.0.0', [ | ||
...validPackage().contents, | ||
dir('symlink_to_dir_outside_package', [ | ||
file('aa', 'aaa'), | ||
]), | ||
dir('symlink_to_dir_outside_package_relative', [ | ||
file('aa', 'aaa'), | ||
]), | ||
dir('b', [file('bb', 'bbb')]), | ||
dir('symlink_to_dir_inside_package', [ | ||
file('bb', 'bbb'), | ||
file('l', 'ttt'), | ||
]), | ||
dir('symlink_to_dir_inside_package_relative', [ | ||
file('bb', 'bbb'), | ||
file('l', 'ttt'), | ||
]), | ||
]).validate( | ||
p.join(sandbox, cachePath, 'hosted', 'pub.dev'), | ||
); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.