Skip to content

Commit

Permalink
Update argument name and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
natebosch committed Jan 16, 2025
1 parent 21a9a74 commit a198283
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkgs/io/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
25 changes: 14 additions & 11 deletions pkgs/io/lib/src/copy_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 <from> <to>`:
/// * 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<void> copyPath(String from, String to, {bool followLinks = true}) async {
Future<void> 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);
Expand All @@ -48,21 +50,22 @@ Future<void> 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 <from> <to>`:
/// * 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);
Expand Down
4 changes: 2 additions & 2 deletions pkgs/io/test/copy_path_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));

Expand Down

0 comments on commit a198283

Please sign in to comment.