mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] remove unused zip verification (#64970)
This is no longer used, in favor of just attempting to unzip and handling the exception.
This commit is contained in:
parent
09a9671ed3
commit
15d18b9e42
@ -93,14 +93,8 @@ abstract class OperatingSystemUtils {
|
|||||||
|
|
||||||
void unzip(File file, Directory targetDirectory);
|
void unzip(File file, Directory targetDirectory);
|
||||||
|
|
||||||
/// Returns true if the ZIP is not corrupt.
|
|
||||||
bool verifyZip(File file);
|
|
||||||
|
|
||||||
void unpack(File gzippedTarFile, Directory targetDirectory);
|
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).
|
/// Compresses a stream using gzip level 1 (faster but larger).
|
||||||
Stream<List<int>> gzipLevel1Stream(Stream<List<int>> stream) {
|
Stream<List<int>> gzipLevel1Stream(Stream<List<int>> stream) {
|
||||||
return stream.cast<List<int>>().transform<List<int>>(gzipLevel1.encoder);
|
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
|
// tar -xzf tarball -C dest
|
||||||
@override
|
@override
|
||||||
void unpack(File gzippedTarFile, Directory targetDirectory) {
|
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
|
@override
|
||||||
File makePipe(String path) {
|
File makePipe(String path) {
|
||||||
_processUtils.runSync(
|
_processUtils.runSync(
|
||||||
@ -335,18 +321,6 @@ class _WindowsUtils extends OperatingSystemUtils {
|
|||||||
_unpackArchive(archive, targetDirectory);
|
_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
|
@override
|
||||||
void unpack(File gzippedTarFile, Directory targetDirectory) {
|
void unpack(File gzippedTarFile, Directory targetDirectory) {
|
||||||
final Archive archive = TarDecoder().decodeBytes(
|
final Archive archive = TarDecoder().decodeBytes(
|
||||||
@ -355,20 +329,6 @@ class _WindowsUtils extends OperatingSystemUtils {
|
|||||||
_unpackArchive(archive, targetDirectory);
|
_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) {
|
void _unpackArchive(Archive archive, Directory targetDirectory) {
|
||||||
for (final ArchiveFile archiveFile in archive.files) {
|
for (final ArchiveFile archiveFile in archive.files) {
|
||||||
// The archive package doesn't correctly set isFile.
|
// 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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:file/file.dart';
|
import 'package:file/file.dart';
|
||||||
import 'package:file/memory.dart';
|
import 'package:file/memory.dart';
|
||||||
import 'package:flutter_tools/src/base/file_system.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', () {
|
testWithoutContext('stream compression level', () {
|
||||||
expect(OperatingSystemUtils.gzipLevel1.level, equals(1));
|
expect(OperatingSystemUtils.gzipLevel1.level, equals(1));
|
||||||
});
|
});
|
||||||
|
@ -312,15 +312,9 @@ class FakeOperatingSystemUtils implements OperatingSystemUtils {
|
|||||||
@override
|
@override
|
||||||
void unzip(File file, Directory targetDirectory) { }
|
void unzip(File file, Directory targetDirectory) { }
|
||||||
|
|
||||||
@override
|
|
||||||
bool verifyZip(File file) => true;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void unpack(File gzippedTarFile, Directory targetDirectory) { }
|
void unpack(File gzippedTarFile, Directory targetDirectory) { }
|
||||||
|
|
||||||
@override
|
|
||||||
bool verifyGzip(File gzippedFile) => true;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<List<int>> gzipLevel1Stream(Stream<List<int>> stream) => stream;
|
Stream<List<int>> gzipLevel1Stream(Stream<List<int>> stream) => stream;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user