Skip to content

Commit 555326b

Browse files
authored
Revert "Replace rsync when unzipping artifacts on a Mac (#126703)" (#127430)
This reverts commit 2b3cd7f. Fixes flutter/flutter#127281.
1 parent 9232834 commit 555326b

2 files changed

Lines changed: 52 additions & 108 deletions

File tree

‎packages/flutter_tools/lib/src/base/os.dart‎

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:meta/meta.dart';
88
import 'package:process/process.dart';
99

1010
import 'common.dart';
11-
import 'error_handling_io.dart';
1211
import 'file_system.dart';
1312
import 'io.dart';
1413
import 'logger.dart';
@@ -424,47 +423,43 @@ class _MacOSUtils extends _PosixUtils {
424423
return _hostPlatform!;
425424
}
426425

427-
/// Unzip into a temporary directory.
428-
///
429-
/// For every file/directory/link in the unzipped file, delete the
430-
/// corresponding entity in the [targetDirectory] before moving from the
431-
/// temporary directory to the [targetDirectory].
426+
// unzip, then rsync
432427
@override
433428
void unzip(File file, Directory targetDirectory) {
434429
if (!_processManager.canRun('unzip')) {
435430
// unzip is not available. this error message is modeled after the download
436431
// error in bin/internal/update_dart_sdk.sh
437432
throwToolExit('Missing "unzip" tool. Unable to extract ${file.path}.\nConsider running "brew install unzip".');
438433
}
439-
final Directory tempDirectory = _fileSystem.systemTempDirectory.createTempSync('flutter_${file.basename}.');
440-
try {
441-
// Unzip to a temporary directory.
434+
if (_processManager.canRun('rsync')) {
435+
final Directory tempDirectory = _fileSystem.systemTempDirectory.createTempSync('flutter_${file.basename}.');
436+
try {
437+
// Unzip to a temporary directory.
438+
_processUtils.runSync(
439+
<String>['unzip', '-o', '-q', file.path, '-d', tempDirectory.path],
440+
throwOnError: true,
441+
verboseExceptions: true,
442+
);
443+
for (final FileSystemEntity unzippedFile in tempDirectory.listSync(followLinks: false)) {
444+
// rsync --delete the unzipped files so files removed from the archive are also removed from the target.
445+
// Add the '-8' parameter to avoid mangling filenames with encodings that do not match the current locale.
446+
_processUtils.runSync(
447+
<String>['rsync', '-8', '-av', '--delete', unzippedFile.path, targetDirectory.path],
448+
throwOnError: true,
449+
verboseExceptions: true,
450+
);
451+
}
452+
} finally {
453+
tempDirectory.deleteSync(recursive: true);
454+
}
455+
} else {
456+
// Fall back to just unzipping.
457+
_logger.printTrace('Unable to find rsync, falling back to direct unzipping.');
442458
_processUtils.runSync(
443-
<String>['unzip', '-o', '-q', file.path, '-d', tempDirectory.path],
459+
<String>['unzip', '-o', '-q', file.path, '-d', targetDirectory.path],
444460
throwOnError: true,
445461
verboseExceptions: true,
446462
);
447-
for (final FileSystemEntity unzippedFile in tempDirectory.listSync(followLinks: false)) {
448-
final FileSystemEntityType fileType = targetDirectory.fileSystem.typeSync(
449-
targetDirectory.fileSystem.path.join(targetDirectory.path, unzippedFile.basename),
450-
followLinks: false,
451-
);
452-
final FileSystemEntity fileToReplace;
453-
if (fileType == FileSystemEntityType.directory) {
454-
fileToReplace = targetDirectory.childDirectory(unzippedFile.basename);
455-
} else if (fileType == FileSystemEntityType.link) {
456-
fileToReplace = targetDirectory.childLink(unzippedFile.basename);
457-
} else {
458-
fileToReplace = targetDirectory.childFile(unzippedFile.basename);
459-
}
460-
// Delete existing version before moving.
461-
ErrorHandlingFileSystem.deleteIfExists(fileToReplace, recursive: true);
462-
unzippedFile.renameSync(fileToReplace.path);
463-
}
464-
} on FileSystemException catch (e) {
465-
_logger.printTrace('${e.message}: ${e.osError}');
466-
} finally {
467-
tempDirectory.deleteSync(recursive: true);
468463
}
469464
}
470465
}

‎packages/flutter_tools/test/general.shard/base/os_test.dart‎

Lines changed: 26 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -626,90 +626,29 @@ void main() {
626626
});
627627

628628
group('unzip on macOS', () {
629-
testWithoutContext('unzip and copy to empty folder', () {
629+
testWithoutContext('falls back to unzip when rsync cannot run', () {
630630
final FileSystem fileSystem = MemoryFileSystem.test();
631+
fakeProcessManager.excludedExecutables.add('rsync');
631632

633+
final BufferLogger logger = BufferLogger.test();
632634
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
633635
fileSystem: fileSystem,
634-
logger: BufferLogger.test(),
635-
platform: FakePlatform(operatingSystem: 'macos'),
636-
processManager: fakeProcessManager,
637-
);
638-
639-
final Directory targetDirectory = fileSystem.currentDirectory;
640-
final Directory tempDirectory = fileSystem.systemTempDirectory.childDirectory('flutter_foo.zip.rand0');
641-
fakeProcessManager.addCommands(<FakeCommand>[
642-
FakeCommand(
643-
command: <String>[
644-
'unzip',
645-
'-o',
646-
'-q',
647-
'foo.zip',
648-
'-d',
649-
tempDirectory.path,
650-
],
651-
onRun: () {
652-
expect(tempDirectory, exists);
653-
tempDirectory.childDirectory('dirA').childFile('fileA').createSync(recursive: true);
654-
tempDirectory.childDirectory('dirB').childFile('fileB').createSync(recursive: true);
655-
},
656-
),
657-
]);
658-
659-
macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory);
660-
expect(fakeProcessManager, hasNoRemainingExpectations);
661-
expect(tempDirectory, isNot(exists));
662-
expect(targetDirectory.childDirectory('dirA').childFile('fileA').existsSync(), isTrue);
663-
expect(targetDirectory.childDirectory('dirB').childFile('fileB').existsSync(), isTrue);
664-
});
665-
666-
testWithoutContext('unzip and copy to preexisting folder', () {
667-
final FileSystem fileSystem = MemoryFileSystem.test();
668-
669-
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
670-
fileSystem: fileSystem,
671-
logger: BufferLogger.test(),
636+
logger: logger,
672637
platform: FakePlatform(operatingSystem: 'macos'),
673638
processManager: fakeProcessManager,
674639
);
675640

676641
final Directory targetDirectory = fileSystem.currentDirectory;
677-
final File origFileA = targetDirectory.childDirectory('dirA').childFile('fileA');
678-
origFileA.createSync(recursive: true);
679-
origFileA.writeAsStringSync('old');
680-
expect(targetDirectory.childDirectory('dirA').childFile('fileA').existsSync(), isTrue);
681-
expect(targetDirectory.childDirectory('dirA').childFile('fileA').readAsStringSync(), 'old');
682-
683-
final Directory tempDirectory = fileSystem.systemTempDirectory.childDirectory('flutter_foo.zip.rand0');
684-
fakeProcessManager.addCommands(<FakeCommand>[
685-
FakeCommand(
686-
command: <String>[
687-
'unzip',
688-
'-o',
689-
'-q',
690-
'foo.zip',
691-
'-d',
692-
tempDirectory.path,
693-
],
694-
onRun: () {
695-
expect(tempDirectory, exists);
696-
final File newFileA = tempDirectory.childDirectory('dirA').childFile('fileA');
697-
newFileA.createSync(recursive: true);
698-
newFileA.writeAsStringSync('new');
699-
tempDirectory.childDirectory('dirB').childFile('fileB').createSync(recursive: true);
700-
},
701-
),
702-
]);
642+
fakeProcessManager.addCommand(FakeCommand(
643+
command: <String>['unzip', '-o', '-q', 'foo.zip', '-d', targetDirectory.path],
644+
));
703645

704-
macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory);
646+
macOSUtils.unzip(fileSystem.file('foo.zip'), targetDirectory);
705647
expect(fakeProcessManager, hasNoRemainingExpectations);
706-
expect(tempDirectory, isNot(exists));
707-
expect(targetDirectory.childDirectory('dirA').childFile('fileA').existsSync(), isTrue);
708-
expect(targetDirectory.childDirectory('dirA').childFile('fileA').readAsStringSync(), 'new');
709-
expect(targetDirectory.childDirectory('dirB').childFile('fileB').existsSync(), isTrue);
648+
expect(logger.traceText, contains('Unable to find rsync'));
710649
});
711650

712-
testWithoutContext('unzip and copy to preexisting folder with type mismatch', () {
651+
testWithoutContext('unzip and rsyncs', () {
713652
final FileSystem fileSystem = MemoryFileSystem.test();
714653

715654
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
@@ -720,10 +659,6 @@ void main() {
720659
);
721660

722661
final Directory targetDirectory = fileSystem.currentDirectory;
723-
final Directory origFileA = targetDirectory.childDirectory('dirA').childDirectory('fileA');
724-
origFileA.createSync(recursive: true);
725-
expect(targetDirectory.childDirectory('dirA').childDirectory('fileA').existsSync(), isTrue);
726-
727662
final Directory tempDirectory = fileSystem.systemTempDirectory.childDirectory('flutter_foo.zip.rand0');
728663
fakeProcessManager.addCommands(<FakeCommand>[
729664
FakeCommand(
@@ -741,13 +676,27 @@ void main() {
741676
tempDirectory.childDirectory('dirB').childFile('fileB').createSync(recursive: true);
742677
},
743678
),
679+
FakeCommand(command: <String>[
680+
'rsync',
681+
'-8',
682+
'-av',
683+
'--delete',
684+
tempDirectory.childDirectory('dirA').path,
685+
targetDirectory.path,
686+
]),
687+
FakeCommand(command: <String>[
688+
'rsync',
689+
'-8',
690+
'-av',
691+
'--delete',
692+
tempDirectory.childDirectory('dirB').path,
693+
targetDirectory.path,
694+
]),
744695
]);
745696

746697
macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory);
747698
expect(fakeProcessManager, hasNoRemainingExpectations);
748699
expect(tempDirectory, isNot(exists));
749-
expect(targetDirectory.childDirectory('dirA').childFile('fileA').existsSync(), isTrue);
750-
expect(targetDirectory.childDirectory('dirB').childFile('fileB').existsSync(), isTrue);
751700
});
752701
});
753702

0 commit comments

Comments
 (0)