Committed by
GitHub
Fix copying asset files for flutter examples. (#1191)
If the target file exists but has a different file size, we need to copy the source file to the target file.
正在显示
2 个修改的文件
包含
5 行增加
和
4 行删除
| @@ -14,8 +14,9 @@ Future<String> copyAssetFile(String src, [String? dst]) async { | @@ -14,8 +14,9 @@ Future<String> copyAssetFile(String src, [String? dst]) async { | ||
| 14 | final target = join(directory.path, dst); | 14 | final target = join(directory.path, dst); |
| 15 | bool exists = await new File(target).exists(); | 15 | bool exists = await new File(target).exists(); |
| 16 | 16 | ||
| 17 | - if (!exists) { | ||
| 18 | - final data = await rootBundle.load(src); | 17 | + final data = await rootBundle.load(src); |
| 18 | + | ||
| 19 | + if (!exists || File(target).lengthSync() != data.lengthInBytes) { | ||
| 19 | final List<int> bytes = | 20 | final List<int> bytes = |
| 20 | data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); | 21 | data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); |
| 21 | await File(target).writeAsBytes(bytes); | 22 | await File(target).writeAsBytes(bytes); |
| @@ -45,8 +45,8 @@ Future<String> copyAssetFile(String src, [String? dst]) async { | @@ -45,8 +45,8 @@ Future<String> copyAssetFile(String src, [String? dst]) async { | ||
| 45 | final target = p.join(directory.path, dst); | 45 | final target = p.join(directory.path, dst); |
| 46 | bool exists = await new File(target).exists(); | 46 | bool exists = await new File(target).exists(); |
| 47 | 47 | ||
| 48 | - if (!exists) { | ||
| 49 | - final data = await rootBundle.load(src); | 48 | + final data = await rootBundle.load(src); |
| 49 | + if (!exists || File(target).lengthSync() != data.lengthInBytes) { | ||
| 50 | final List<int> bytes = | 50 | final List<int> bytes = |
| 51 | data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); | 51 | data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); |
| 52 | await (await File(target).create(recursive: true)).writeAsBytes(bytes); | 52 | await (await File(target).create(recursive: true)).writeAsBytes(bytes); |
-
请 注册 或 登录 后发表评论