From ccdaa3704350c5f49e4a3cfd3590d1b92880743b Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Thu, 8 Oct 2020 13:40:01 -0700 Subject: [PATCH] Remove the .zip method from OSUtils, as it was not used (#67367) We used to use zip to verify the integrity of downloaded zip archives, but we now use unzip. This removes the .zip method from OperatingSystemUtils. --- packages/flutter_tools/lib/src/base/os.dart | 41 --------------- .../test/general.shard/base/os_test.dart | 50 ------------------- packages/flutter_tools/test/src/context.dart | 3 -- 3 files changed, 94 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/os.dart b/packages/flutter_tools/lib/src/base/os.dart index 2efd6b7639..8fd9a98ac4 100644 --- a/packages/flutter_tools/lib/src/base/os.dart +++ b/packages/flutter_tools/lib/src/base/os.dart @@ -90,8 +90,6 @@ abstract class OperatingSystemUtils { /// Return the File representing a new pipe. File makePipe(String path); - void zip(Directory data, File zipFile); - void unzip(File file, Directory targetDirectory); void unpack(File gzippedTarFile, Directory targetDirectory); @@ -206,30 +204,6 @@ class _PosixUtils extends OperatingSystemUtils { ).toList(); } - @override - void zip(Directory data, File zipFile) { - try { - _processUtils.runSync( - ['zip', '-r', '-q', zipFile.path, '.'], - workingDirectory: data.path, - throwOnError: true, - verboseExceptions: true, - ); - } on ArgumentError { - // zip is not available. this error message is modeled after the download - // error in bin/internal/update_dart_sdk.sh - String message = 'Please install zip.'; - if (_platform.isMacOS) { - message = 'Consider running "brew install zip".'; - } else if (_platform.isLinux) { - message = 'Consider running "sudo apt-get install zip".'; - } - throwToolExit( - 'Missing "zip" tool. Unable to compress ${data.path}.\n$message' - ); - } - } - // unzip -o -q zipfile -d dest @override void unzip(File file, Directory targetDirectory) { @@ -342,21 +316,6 @@ class _WindowsUtils extends OperatingSystemUtils { return [_fileSystem.file(lines.first.trim())]; } - @override - void zip(Directory data, File zipFile) { - final Archive archive = Archive(); - for (final FileSystemEntity entity in data.listSync(recursive: true)) { - if (entity is! File) { - continue; - } - final File file = entity as File; - final String path = file.fileSystem.path.relative(file.path, from: data.path); - final List bytes = file.readAsBytesSync(); - archive.addFile(ArchiveFile(path, bytes.length, bytes)); - } - zipFile.writeAsBytesSync(ZipEncoder().encode(archive), flush: true); - } - @override void unzip(File file, Directory targetDirectory) { final Archive archive = ZipDecoder().decodeBytes(file.readAsBytesSync()); 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 588c11d163..d2e77daefe 100644 --- a/packages/flutter_tools/test/general.shard/base/os_test.dart +++ b/packages/flutter_tools/test/general.shard/base/os_test.dart @@ -192,56 +192,6 @@ void main() { ); }); - testWithoutContext('If zip throws an ArgumentError, display an install message', () { - final FileSystem fileSystem = MemoryFileSystem.test(); - when(mockProcessManager.runSync( - ['zip', '-r', '-q', 'foo.zip', '.'], - workingDirectory: anyNamed('workingDirectory'), - )).thenThrow(ArgumentError()); - - final OperatingSystemUtils linuxOsUtils = OperatingSystemUtils( - fileSystem: fileSystem, - logger: BufferLogger.test(), - platform: FakePlatform(operatingSystem: 'linux'), - processManager: mockProcessManager, - ); - - expect( - () => linuxOsUtils.zip(fileSystem.currentDirectory, fileSystem.file('foo.zip')), - throwsToolExit( - message: 'Missing "zip" tool. Unable to compress /.\n' - 'Consider running "sudo apt-get install zip".'), - ); - - final OperatingSystemUtils macOSUtils = OperatingSystemUtils( - fileSystem: fileSystem, - logger: BufferLogger.test(), - platform: FakePlatform(operatingSystem: 'macos'), - processManager: mockProcessManager, - ); - - expect( - () => macOSUtils.zip(fileSystem.currentDirectory, fileSystem.file('foo.zip')), - throwsToolExit - (message: 'Missing "zip" tool. Unable to compress /.\n' - 'Consider running "brew install zip".'), - ); - - final OperatingSystemUtils unknownOsUtils = OperatingSystemUtils( - fileSystem: fileSystem, - logger: BufferLogger.test(), - platform: FakePlatform(operatingSystem: 'fuchsia'), - processManager: mockProcessManager, - ); - - expect( - () => unknownOsUtils.zip(fileSystem.currentDirectory, fileSystem.file('foo.zip')), - throwsToolExit - (message: 'Missing "zip" tool. Unable to compress /.\n' - 'Please install zip.'), - ); - }); - 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 97c4633aa8..a653e7ebf0 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -306,9 +306,6 @@ class FakeOperatingSystemUtils implements OperatingSystemUtils { @override File makePipe(String path) => null; - @override - void zip(Directory data, File zipFile) { } - @override void unzip(File file, Directory targetDirectory) { }