diff --git a/pkgs/io/CHANGELOG.md b/pkgs/io/CHANGELOG.md index f5e99881c..8c0057f2b 100644 --- a/pkgs/io/CHANGELOG.md +++ b/pkgs/io/CHANGELOG.md @@ -1,6 +1,6 @@ ## 1.1.0-wip -* Add a `followLinks` argument to `copyPath` and `copyPathSync`. +* Add a `deepCopyLinks` argument to `copyPath` and `copyPathSync`. ## 1.0.5 diff --git a/pkgs/io/lib/src/copy_path.dart b/pkgs/io/lib/src/copy_path.dart index ce1fd5a7c..8a1c3ca46 100644 --- a/pkgs/io/lib/src/copy_path.dart +++ b/pkgs/io/lib/src/copy_path.dart @@ -19,21 +19,23 @@ bool _doNothing(String from, String to) { /// Copies all of the files in the [from] directory to [to]. /// /// This is similar to `cp -R `: -/// * Symlinks are supported. /// * 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. +/// * If [deepCopyLinks] is `true` (the default) then links are followed and +/// the content of linked directories and files are copied entirely. If +/// `false` then new [Link] file system entities are created linking to the +/// same target the links under [from]. /// /// Returns a future that completes when complete. -Future copyPath(String from, String to, {bool followLinks = true}) async { +Future copyPath(String from, String to, + {bool deepCopyLinks = true}) async { if (_doNothing(from, to)) { return; } await Directory(to).create(recursive: true); await for (final file - in Directory(from).list(recursive: true, followLinks: followLinks)) { + in Directory(from).list(recursive: true, followLinks: deepCopyLinks)) { final copyTo = p.join(to, p.relative(file.path, from: from)); if (file is Directory) { await Directory(copyTo).create(recursive: true); @@ -48,21 +50,22 @@ Future copyPath(String from, String to, {bool followLinks = true}) async { /// Copies all of the files in the [from] directory to [to]. /// /// This is similar to `cp -R `: -/// * Symlinks are supported. /// * 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. +/// * If [deepCopyLinks] is `true` (the default) then links are followed and +/// the content of linked directories and files are copied entirely. If +/// `false` then new [Link] file system entities are created linking to the +/// same target the links under [from]. /// /// This action is performed synchronously (blocking I/O). -void copyPathSync(String from, String to, {bool followLinks = true}) { +void copyPathSync(String from, String to, {bool deepCopyLinks = true}) { if (_doNothing(from, to)) { return; } Directory(to).createSync(recursive: true); - for (final file - in Directory(from).listSync(recursive: true, followLinks: followLinks)) { + for (final file in Directory(from) + .listSync(recursive: true, followLinks: deepCopyLinks)) { final copyTo = p.join(to, p.relative(file.path, from: from)); if (file is Directory) { Directory(copyTo).createSync(recursive: true); diff --git a/pkgs/io/test/copy_path_test.dart b/pkgs/io/test/copy_path_test.dart index f34519956..af3cb36a0 100644 --- a/pkgs/io/test/copy_path_test.dart +++ b/pkgs/io/test/copy_path_test.dart @@ -51,7 +51,7 @@ void main() { test('are shallow copied with deepCopyLinks: false in copyPath', () async { await copyPath( - followLinks: false, + deepCopyLinks: false, p.join(d.sandbox, _parentDir), p.join(d.sandbox, _copyDir)); @@ -63,7 +63,7 @@ void main() { test('are shallow copied with deepCopyLinks: false in copyPathAsync', () async { copyPathSync( - followLinks: false, + deepCopyLinks: false, p.join(d.sandbox, _parentDir), p.join(d.sandbox, _copyDir));