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.
This commit is contained in:
parent
96ae589a2e
commit
ccdaa37043
@ -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(
|
||||
<String>['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 <File>[_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<int> 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());
|
||||
|
@ -192,56 +192,6 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('If zip throws an ArgumentError, display an install message', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
when(mockProcessManager.runSync(
|
||||
<String>['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));
|
||||
});
|
||||
|
@ -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) { }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user