mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[flutter_tools] Handle empty gzip file on Windows (#54679)
* [flutter_tools] Handle empty gzip file on Windows * Update packages/flutter_tools/test/general.shard/base/os_test.dart Co-Authored-By: Jonah Williams <jonahwilliams@google.com> * Update packages/flutter_tools/test/general.shard/base/os_test.dart Co-Authored-By: Jonah Williams <jonahwilliams@google.com> * Update packages/flutter_tools/test/general.shard/base/os_test.dart Co-Authored-By: Jonah Williams <jonahwilliams@google.com> Co-authored-by: Jonah Williams <jonahwilliams@google.com>
This commit is contained in:
parent
9cc69d47a5
commit
57dd045cef
@ -362,6 +362,8 @@ class _WindowsUtils extends OperatingSystemUtils {
|
||||
return false;
|
||||
} on ArchiveException catch (_) {
|
||||
return false;
|
||||
} on RangeError catch (_) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
// 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/io.dart';
|
||||
@ -87,9 +89,64 @@ 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));
|
||||
});
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
class MockFileSystem extends Mock implements FileSystem {}
|
||||
class MockFile extends Mock implements File {}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user