Skip to content
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

copyPath/copyPathSync: expose parameter followLinks #1267

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pkgs/io/lib/src/copy_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ bool _doNothing(String from, String to) {
/// * Existing files are over-written, if any.
/// * If [to] is within [from], throws [ArgumentError] (an infinite operation).
/// * If [from] and [to] are canonically the same, no operation occurs.
/// * If [followLinks] is `true`, then working links are reported as
/// directories or files, and links to directories are recursed into.
///
/// Returns a future that completes when complete.
Future<void> copyPath(String from, String to) async {
Future<void> copyPath(String from, String to, {bool followLinks = true}) async {
if (_doNothing(from, to)) {
return;
}
await Directory(to).create(recursive: true);
await for (final file in Directory(from).list(recursive: true)) {
await for (final file
in Directory(from).list(recursive: true, followLinks: followLinks)) {
final copyTo = p.join(to, p.relative(file.path, from: from));
if (file is Directory) {
await Directory(copyTo).create(recursive: true);
Expand All @@ -49,14 +52,17 @@ Future<void> copyPath(String from, String to) async {
/// * Existing files are over-written, if any.
/// * If [to] is within [from], throws [ArgumentError] (an infinite operation).
/// * If [from] and [to] are canonically the same, no operation occurs.
/// * If [followLinks] is `true`, then working links are reported as
/// directories or files, and links to directories are recursed into.
///
/// This action is performed synchronously (blocking I/O).
void copyPathSync(String from, String to) {
void copyPathSync(String from, String to, {bool followLinks = true}) {
if (_doNothing(from, to)) {
return;
}
Directory(to).createSync(recursive: true);
for (final file in Directory(from).listSync(recursive: true)) {
for (final file
in Directory(from).listSync(recursive: true, followLinks: followLinks)) {
final copyTo = p.join(to, p.relative(file.path, from: from));
if (file is Directory) {
Directory(copyTo).createSync(recursive: true);
Expand Down
Loading