From f847272fc70bcf630da80e8cf62e6fcaa5ba8b9e Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 18 Oct 2017 13:46:17 -0700 Subject: [PATCH] Make FLX construction atomic (#12604) This patch also makes it possible to create FLX files with no extension. Previously, the zip tool would add the ".zip" extension if the output file lacked an extension. --- packages/flutter_tools/lib/src/zip.dart | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/zip.dart b/packages/flutter_tools/lib/src/zip.dart index f4107f052b..b0121eab5a 100644 --- a/packages/flutter_tools/lib/src/zip.dart +++ b/packages/flutter_tools/lib/src/zip.dart @@ -62,8 +62,9 @@ class _ZipToolBuilder extends ZipBuilder { return; } - if (outFile.existsSync()) - outFile.deleteSync(); + final File tmpFile = fs.file('${outFile.path}.tmp'); + if (tmpFile.existsSync()) + tmpFile.deleteSync(); if (zipBuildDir.existsSync()) zipBuildDir.deleteSync(recursive: true); @@ -87,7 +88,7 @@ class _ZipToolBuilder extends ZipBuilder { final Iterable compressedNames = _getCompressedNames(); if (compressedNames.isNotEmpty) { await runCheckedAsync( - ['zip', '-q', outFile.absolute.path]..addAll(compressedNames), + ['zip', '-q', tmpFile.absolute.path]..addAll(compressedNames), workingDirectory: zipBuildDir.path ); } @@ -95,10 +96,12 @@ class _ZipToolBuilder extends ZipBuilder { final Iterable storedNames = _getStoredNames(); if (storedNames.isNotEmpty) { await runCheckedAsync( - ['zip', '-q', '-0', outFile.absolute.path]..addAll(storedNames), + ['zip', '-q', '-0', tmpFile.absolute.path]..addAll(storedNames), workingDirectory: zipBuildDir.path ); } + + tmpFile.renameSync(outFile.absolute.path); } static const List _kNoCompressFileExtensions = const ['.png', '.jpg'];