Replace rsync when unzipping artifacts on a Mac (#126703)

Instead of using rsync, which has caused errors in the past (https://github.com/flutter/flutter/issues/99785), delete the file/directory/link prior to moving it.

Hopefully should let us stop double zipping the FlutterMacOS.framework in the engine: https://github.com/flutter/engine/pull/41306/files

Part of https://github.com/flutter/flutter/issues/126016.
This commit is contained in:
Victoria Ashworth
2023-05-16 11:58:06 -05:00
committed by GitHub
parent a3b38aa8f3
commit 2b3cd7f4d9
2 changed files with 121 additions and 65 deletions

View File

@@ -626,29 +626,7 @@ void main() {
});
group('unzip on macOS', () {
testWithoutContext('falls back to unzip when rsync cannot run', () {
final FileSystem fileSystem = MemoryFileSystem.test();
fakeProcessManager.excludedExecutables.add('rsync');
final BufferLogger logger = BufferLogger.test();
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: logger,
platform: FakePlatform(operatingSystem: 'macos'),
processManager: fakeProcessManager,
);
final Directory targetDirectory = fileSystem.currentDirectory;
fakeProcessManager.addCommand(FakeCommand(
command: <String>['unzip', '-o', '-q', 'foo.zip', '-d', targetDirectory.path],
));
macOSUtils.unzip(fileSystem.file('foo.zip'), targetDirectory);
expect(fakeProcessManager, hasNoRemainingExpectations);
expect(logger.traceText, contains('Unable to find rsync'));
});
testWithoutContext('unzip and rsyncs', () {
testWithoutContext('unzip and copy to empty folder', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
@@ -676,27 +654,100 @@ void main() {
tempDirectory.childDirectory('dirB').childFile('fileB').createSync(recursive: true);
},
),
FakeCommand(command: <String>[
'rsync',
'-8',
'-av',
'--delete',
tempDirectory.childDirectory('dirA').path,
targetDirectory.path,
]),
FakeCommand(command: <String>[
'rsync',
'-8',
'-av',
'--delete',
tempDirectory.childDirectory('dirB').path,
targetDirectory.path,
]),
]);
macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory);
expect(fakeProcessManager, hasNoRemainingExpectations);
expect(tempDirectory, isNot(exists));
expect(targetDirectory.childDirectory('dirA').childFile('fileA').existsSync(), isTrue);
expect(targetDirectory.childDirectory('dirB').childFile('fileB').existsSync(), isTrue);
});
testWithoutContext('unzip and copy to preexisting folder', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'macos'),
processManager: fakeProcessManager,
);
final Directory targetDirectory = fileSystem.currentDirectory;
final File origFileA = targetDirectory.childDirectory('dirA').childFile('fileA');
origFileA.createSync(recursive: true);
origFileA.writeAsStringSync('old');
expect(targetDirectory.childDirectory('dirA').childFile('fileA').existsSync(), isTrue);
expect(targetDirectory.childDirectory('dirA').childFile('fileA').readAsStringSync(), 'old');
final Directory tempDirectory = fileSystem.systemTempDirectory.childDirectory('flutter_foo.zip.rand0');
fakeProcessManager.addCommands(<FakeCommand>[
FakeCommand(
command: <String>[
'unzip',
'-o',
'-q',
'foo.zip',
'-d',
tempDirectory.path,
],
onRun: () {
expect(tempDirectory, exists);
final File newFileA = tempDirectory.childDirectory('dirA').childFile('fileA');
newFileA.createSync(recursive: true);
newFileA.writeAsStringSync('new');
tempDirectory.childDirectory('dirB').childFile('fileB').createSync(recursive: true);
},
),
]);
macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory);
expect(fakeProcessManager, hasNoRemainingExpectations);
expect(tempDirectory, isNot(exists));
expect(targetDirectory.childDirectory('dirA').childFile('fileA').existsSync(), isTrue);
expect(targetDirectory.childDirectory('dirA').childFile('fileA').readAsStringSync(), 'new');
expect(targetDirectory.childDirectory('dirB').childFile('fileB').existsSync(), isTrue);
});
testWithoutContext('unzip and copy to preexisting folder with type mismatch', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'macos'),
processManager: fakeProcessManager,
);
final Directory targetDirectory = fileSystem.currentDirectory;
final Directory origFileA = targetDirectory.childDirectory('dirA').childDirectory('fileA');
origFileA.createSync(recursive: true);
expect(targetDirectory.childDirectory('dirA').childDirectory('fileA').existsSync(), isTrue);
final Directory tempDirectory = fileSystem.systemTempDirectory.childDirectory('flutter_foo.zip.rand0');
fakeProcessManager.addCommands(<FakeCommand>[
FakeCommand(
command: <String>[
'unzip',
'-o',
'-q',
'foo.zip',
'-d',
tempDirectory.path,
],
onRun: () {
expect(tempDirectory, exists);
tempDirectory.childDirectory('dirA').childFile('fileA').createSync(recursive: true);
tempDirectory.childDirectory('dirB').childFile('fileB').createSync(recursive: true);
},
),
]);
macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory);
expect(fakeProcessManager, hasNoRemainingExpectations);
expect(tempDirectory, isNot(exists));
expect(targetDirectory.childDirectory('dirA').childFile('fileA').existsSync(), isTrue);
expect(targetDirectory.childDirectory('dirB').childFile('fileB').existsSync(), isTrue);
});
});