Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

copyPath: add parameter followLinks #97

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.0.5-wip

* Require Dart 3.0.
* `copyPath`/`copyPathSync`: expose parameter `followLinks`.

## 1.0.4

Expand Down
14 changes: 10 additions & 4 deletions 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