-
Notifications
You must be signed in to change notification settings - Fork 229
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
fix: symlinks handling #3298
base: master
Are you sure you want to change the base?
fix: symlinks handling #3298
Conversation
I'm a bit unsure if we want to support this, how does it handle cycles? Might it not be better to just ask advanced users to copy files if they need to include them in multiple locations. They can wrap their |
It’s common use case for macOS/iOS plug-ins, third party libraries in ffi plugins etc In our case it forces us to remove directory with symlink to common scripts before publish pubignore also does not solve it since this check is done prior to application of ignore rules |
The only failing test should be one which ensures Previous behavior (pub bundled in dart 2.12 and behavior in current PR):
Current behavior:
If you insist this is expected behavior: I could try to move the check after resolving of ignored files and allow only ignored directory symlinks |
Hmm, it seems that in windows it fails to list dirrectory with loops in symlinks It differs from what is done on posix-like systems
|
Besides the cycle-handling this is looking quite good! |
jfyi: I had no time to reslove windows-related bugs lately, will continue in a few days |
I have done a bit of research, and it seems that both on windows, mac and linux By that logic we probably don't need to do anything explicit to prevent circularities. We just handle that exception. I'll try to make a merge, and an update without the check for circularities. |
Hmm - seems the CI doesn't agree quite with my research. On mac it seems contents of sufficiently nested directories is not listed. And on windows sufficiently nested links exists as Link but not as a Directory... |
Does that matter if it is documented? It would still work for all use cases where everything is set up correctly right? |
Yeah - perhaps we don't need to care that much about symlink cycles. If you have them, you kind of set yourself up for trouble... |
@jonasfj I reinstated some symlink detection. I think™ this works.
Could you do a sanity check? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will work.
lib/src/package.dart
Outdated
} on FileSystemException catch (e) { | ||
throw DataException( | ||
'Could not resolve symbolic link $path. $e', | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
} on FileSystemException catch (e) { | |
throw DataException( | |
'Could not resolve symbolic link $path. $e', | |
); | |
} | |
} on FileSystemException catch (e) { | |
if (!link.existsSync()) { | |
return; | |
} | |
throw DataException( | |
'Could not resolve symbolic link $path. $e', | |
); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test/package_list_files_test.dart
Outdated
createDirectorySymlink( | ||
p.join(d.sandbox, appPath, 'subdir', 'symlink'), | ||
'..', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making a d.link
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Co-authored-by: Jonas Finnemann Jensen <jopsen@gmail.com>
test/lish/symlinks_test.dart
Outdated
await dir(appPath, [ | ||
dir('b', [file('bb', 'bbb')]), | ||
]).create(); | ||
Link(p.join(sandbox, appPath, 'symlink_to_dir_outside_package')) | ||
.createSync(p.join(sandbox, 'a')); | ||
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')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use link
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test/link_descriptor.dart
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Belongs in the test/descriptor/
folder:
https://github.com/dart-lang/pub/tree/master/test/descriptor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test/link_descriptor.dart
Outdated
d.Descriptor link(String name, String target, {bool forceDirectory = false}) { | ||
return LinkDescriptor(name, target, forceDirectory: forceDirectory); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this in test/descriptor.dart
, I think..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test/lish/symlinks_test.dart
Outdated
import 'package:tar/tar.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../descriptor.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import '../descriptor.dart'; | |
import '../descriptor.dart' as d; |
To follow the pattern we have in other files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
fixes: #3143