Commit f847272f authored by Adam Barth's avatar Adam Barth Committed by GitHub

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.
parent 07908916
...@@ -62,8 +62,9 @@ class _ZipToolBuilder extends ZipBuilder { ...@@ -62,8 +62,9 @@ class _ZipToolBuilder extends ZipBuilder {
return; return;
} }
if (outFile.existsSync()) final File tmpFile = fs.file('${outFile.path}.tmp');
outFile.deleteSync(); if (tmpFile.existsSync())
tmpFile.deleteSync();
if (zipBuildDir.existsSync()) if (zipBuildDir.existsSync())
zipBuildDir.deleteSync(recursive: true); zipBuildDir.deleteSync(recursive: true);
...@@ -87,7 +88,7 @@ class _ZipToolBuilder extends ZipBuilder { ...@@ -87,7 +88,7 @@ class _ZipToolBuilder extends ZipBuilder {
final Iterable<String> compressedNames = _getCompressedNames(); final Iterable<String> compressedNames = _getCompressedNames();
if (compressedNames.isNotEmpty) { if (compressedNames.isNotEmpty) {
await runCheckedAsync( await runCheckedAsync(
<String>['zip', '-q', outFile.absolute.path]..addAll(compressedNames), <String>['zip', '-q', tmpFile.absolute.path]..addAll(compressedNames),
workingDirectory: zipBuildDir.path workingDirectory: zipBuildDir.path
); );
} }
...@@ -95,10 +96,12 @@ class _ZipToolBuilder extends ZipBuilder { ...@@ -95,10 +96,12 @@ class _ZipToolBuilder extends ZipBuilder {
final Iterable<String> storedNames = _getStoredNames(); final Iterable<String> storedNames = _getStoredNames();
if (storedNames.isNotEmpty) { if (storedNames.isNotEmpty) {
await runCheckedAsync( await runCheckedAsync(
<String>['zip', '-q', '-0', outFile.absolute.path]..addAll(storedNames), <String>['zip', '-q', '-0', tmpFile.absolute.path]..addAll(storedNames),
workingDirectory: zipBuildDir.path workingDirectory: zipBuildDir.path
); );
} }
tmpFile.renameSync(outFile.absolute.path);
} }
static const List<String> _kNoCompressFileExtensions = const <String>['.png', '.jpg']; static const List<String> _kNoCompressFileExtensions = const <String>['.png', '.jpg'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment