Unverified Commit 57dd045c authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[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: 's avatarJonah Williams <jonahwilliams@google.com>

* Update packages/flutter_tools/test/general.shard/base/os_test.dart
Co-Authored-By: 's avatarJonah Williams <jonahwilliams@google.com>

* Update packages/flutter_tools/test/general.shard/base/os_test.dart
Co-Authored-By: 's avatarJonah Williams <jonahwilliams@google.com>
Co-authored-by: 's avatarJonah Williams <jonahwilliams@google.com>
parent 9cc69d47
......@@ -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 {}
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