From 3e020921c68556ff48cfcd60d7150980aaf77b6d Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Wed, 7 Jan 2026 03:52:21 -0800 Subject: [PATCH] [dartdev] Delete and create dylibs instead of truncate TEST=Tested locally. Will add a test case upstream in dart-lang/native and roll that in. Bug: https://github.com/dart-lang/native/issues/2921 Change-Id: I8010131cc70afe5bcee30edf076f18efe0c9a8c4 Cq-Include-Trybots: luci.dart.try:pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-win-release-try,pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-mac-release-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471240 Reviewed-by: Martin Kustermann Commit-Queue: Daco Harkes --- pkg/dartdev/lib/src/native_assets_bundling.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/dartdev/lib/src/native_assets_bundling.dart b/pkg/dartdev/lib/src/native_assets_bundling.dart index eaf12c6f471..1a3ade69ec9 100644 --- a/pkg/dartdev/lib/src/native_assets_bundling.dart +++ b/pkg/dartdev/lib/src/native_assets_bundling.dart @@ -164,7 +164,12 @@ extension on DataAsset { extension on Uri { Future copyTo(Uri targetUri) async { - await File.fromUri(targetUri).create(recursive: true); + var targetFile = File.fromUri(targetUri); + // File.copy truncates. So, first to ensure that if it was dlopened it + // doesn't get truncated on disk. + // https://github.com/dart-lang/sdk/issues/62361 + if (await targetFile.exists()) await targetFile.delete(); + await targetFile.create(recursive: true); await File.fromUri(this).copy(targetUri.toFilePath()); } }