Unverified Commit 15d18b9e authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove unused zip verification (#64970)

This is no longer used, in favor of just attempting to unzip and handling the exception.
parent 09a9671e
......@@ -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<List<int>> gzipLevel1Stream(Stream<List<int>> stream) {
return stream.cast<List<int>>().transform<List<int>>(gzipLevel1.encoder);
......@@ -230,10 +224,6 @@ class _PosixUtils extends OperatingSystemUtils {
);
}
@override
bool verifyZip(File zipFile) =>
_processUtils.exitsHappySync(<String>['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(<String>['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.
......
......@@ -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(<int>[
// 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));
});
......
......@@ -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<List<int>> gzipLevel1Stream(Stream<List<int>> stream) => stream;
......
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