From 15d18b9e424aba08885c01a29c992f6cfd40b6d8 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 31 Aug 2020 13:26:38 -0700 Subject: [PATCH] [flutter_tools] remove unused zip verification (#64970) This is no longer used, in favor of just attempting to unzip and handling the exception. --- packages/flutter_tools/lib/src/base/os.dart | 40 -------------- .../test/general.shard/base/os_test.dart | 55 ------------------- packages/flutter_tools/test/src/context.dart | 6 -- 3 files changed, 101 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/os.dart b/packages/flutter_tools/lib/src/base/os.dart index 0c7929cc916..fbfc9dc8dd6 100644 --- a/packages/flutter_tools/lib/src/base/os.dart +++ b/packages/flutter_tools/lib/src/base/os.dart @@ -93,14 +93,8 @@ abstract class OperatingSystemUtils { void unzip(File file, Directory targetDirectory); - /// Returns true if the ZIP is not corrupt. - bool verifyZip(File file); - void unpack(File gzippedTarFile, Directory targetDirectory); - /// Returns true if the gzip is not corrupt (does not check tar). - bool verifyGzip(File gzippedFile); - /// Compresses a stream using gzip level 1 (faster but larger). Stream> gzipLevel1Stream(Stream> stream) { return stream.cast>().transform>(gzipLevel1.encoder); @@ -230,10 +224,6 @@ class _PosixUtils extends OperatingSystemUtils { ); } - @override - bool verifyZip(File zipFile) => - _processUtils.exitsHappySync(['unzip', '-t', '-qq', zipFile.path]); - // tar -xzf tarball -C dest @override void unpack(File gzippedTarFile, Directory targetDirectory) { @@ -243,10 +233,6 @@ class _PosixUtils extends OperatingSystemUtils { ); } - @override - bool verifyGzip(File gzippedFile) => - _processUtils.exitsHappySync(['gzip', '-t', gzippedFile.path]); - @override File makePipe(String path) { _processUtils.runSync( @@ -335,18 +321,6 @@ class _WindowsUtils extends OperatingSystemUtils { _unpackArchive(archive, targetDirectory); } - @override - bool verifyZip(File zipFile) { - try { - ZipDecoder().decodeBytes(zipFile.readAsBytesSync(), verify: true); - } on FileSystemException catch (_) { - return false; - } on ArchiveException catch (_) { - return false; - } - return true; - } - @override void unpack(File gzippedTarFile, Directory targetDirectory) { final Archive archive = TarDecoder().decodeBytes( @@ -355,20 +329,6 @@ class _WindowsUtils extends OperatingSystemUtils { _unpackArchive(archive, targetDirectory); } - @override - bool verifyGzip(File gzipFile) { - try { - GZipDecoder().decodeBytes(gzipFile.readAsBytesSync(), verify: true); - } on FileSystemException catch (_) { - return false; - } on ArchiveException catch (_) { - return false; - } on RangeError catch (_) { - return false; - } - return true; - } - void _unpackArchive(Archive archive, Directory targetDirectory) { for (final ArchiveFile archiveFile in archive.files) { // The archive package doesn't correctly set isFile. diff --git a/packages/flutter_tools/test/general.shard/base/os_test.dart b/packages/flutter_tools/test/general.shard/base/os_test.dart index a2e7ac16ab2..370c49181ba 100644 --- a/packages/flutter_tools/test/general.shard/base/os_test.dart +++ b/packages/flutter_tools/test/general.shard/base/os_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:typed_data'; - import 'package:file/file.dart'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; @@ -114,59 +112,6 @@ void main() { ); }); - group('gzip on Windows:', () { - testWithoutContext('verifyGzip returns false on a FileSystemException', () { - final MockFileSystem fileSystem = MockFileSystem(); - final MockFile mockFile = MockFile(); - when(fileSystem.file(any)).thenReturn(mockFile); - when(mockFile.readAsBytesSync()).thenThrow( - const FileSystemException('error'), - ); - final OperatingSystemUtils osUtils = OperatingSystemUtils( - fileSystem: fileSystem, - logger: BufferLogger.test(), - platform: FakePlatform(operatingSystem: 'windows'), - processManager: mockProcessManager, - ); - - expect(osUtils.verifyGzip(mockFile), isFalse); - }); - - testWithoutContext('verifyGzip returns false on an ArchiveException', () { - final MockFileSystem fileSystem = MockFileSystem(); - final MockFile mockFile = MockFile(); - when(fileSystem.file(any)).thenReturn(mockFile); - when(mockFile.readAsBytesSync()).thenReturn(Uint8List.fromList([ - // Anything other than the magic header: 0x1f, 0x8b. - 0x01, - 0x02, - ])); - final OperatingSystemUtils osUtils = OperatingSystemUtils( - fileSystem: fileSystem, - logger: BufferLogger.test(), - platform: FakePlatform(operatingSystem: 'windows'), - processManager: mockProcessManager, - ); - - expect(osUtils.verifyGzip(mockFile), isFalse); - }); - - testWithoutContext('verifyGzip returns false on an empty file', () { - final MockFileSystem fileSystem = MockFileSystem(); - final MockFile mockFile = MockFile(); - when(fileSystem.file(any)).thenReturn(mockFile); - when(mockFile.readAsBytesSync()).thenReturn(Uint8List(0)); - final OperatingSystemUtils osUtils = OperatingSystemUtils( - fileSystem: fileSystem, - logger: BufferLogger.test(), - platform: FakePlatform(operatingSystem: 'windows'), - processManager: mockProcessManager, - ); - - expect(osUtils.verifyGzip(mockFile), isFalse); - }); - }); - testWithoutContext('stream compression level', () { expect(OperatingSystemUtils.gzipLevel1.level, equals(1)); }); diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index 64cf97f6c59..559f3620345 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -312,15 +312,9 @@ class FakeOperatingSystemUtils implements OperatingSystemUtils { @override void unzip(File file, Directory targetDirectory) { } - @override - bool verifyZip(File file) => true; - @override void unpack(File gzippedTarFile, Directory targetDirectory) { } - @override - bool verifyGzip(File gzippedFile) => true; - @override Stream> gzipLevel1Stream(Stream> stream) => stream;