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

[io] copyPath/copyPathSync: expose parameter followLinks #1267

Merged
merged 13 commits into from
Jan 17, 2025
4 changes: 4 additions & 0 deletions pkgs/io/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0-wip

* Add a `followLinks` argument to `copyPath` and `copyPathSync`.

## 1.0.5

* Require Dart 3.4.
Expand Down
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
2 changes: 1 addition & 1 deletion pkgs/io/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: io
description: >-
Utilities for the Dart VM Runtime including support for ANSI colors, file
copying, and standard exit code values.
version: 1.0.5
version: 1.1.0-wip
repository: https://github.com/dart-lang/tools/tree/main/pkgs/io

environment:
Expand Down
Loading