@@ -626,29 +626,90 @@ void main() {
626626 });
627627
628628 group ('unzip on macOS' , () {
629- testWithoutContext ('falls back to unzip when rsync cannot run ' , () {
629+ testWithoutContext ('unzip and copy to empty folder ' , () {
630630 final FileSystem fileSystem = MemoryFileSystem .test ();
631- fakeProcessManager.excludedExecutables.add ('rsync' );
632631
633- final BufferLogger logger = BufferLogger .test ();
634632 final OperatingSystemUtils macOSUtils = OperatingSystemUtils (
635633 fileSystem: fileSystem,
636- logger: logger,
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 (),
637672 platform: FakePlatform (operatingSystem: 'macos' ),
638673 processManager: fakeProcessManager,
639674 );
640675
641676 final Directory targetDirectory = fileSystem.currentDirectory;
642- fakeProcessManager.addCommand (FakeCommand (
643- command: < String > ['unzip' , '-o' , '-q' , 'foo.zip' , '-d' , targetDirectory.path],
644- ));
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+ ]);
645703
646- macOSUtils.unzip (fileSystem.file ('foo.zip' ), targetDirectory );
704+ macOSUtils.unzip (fileSystem.file ('foo.zip' ), fileSystem.currentDirectory );
647705 expect (fakeProcessManager, hasNoRemainingExpectations);
648- expect (logger.traceText, contains ('Unable to find rsync' ));
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);
649710 });
650711
651- testWithoutContext ('unzip and rsyncs ' , () {
712+ testWithoutContext ('unzip and copy to preexisting folder with type mismatch ' , () {
652713 final FileSystem fileSystem = MemoryFileSystem .test ();
653714
654715 final OperatingSystemUtils macOSUtils = OperatingSystemUtils (
@@ -659,6 +720,10 @@ void main() {
659720 );
660721
661722 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+
662727 final Directory tempDirectory = fileSystem.systemTempDirectory.childDirectory ('flutter_foo.zip.rand0' );
663728 fakeProcessManager.addCommands (< FakeCommand > [
664729 FakeCommand (
@@ -676,27 +741,13 @@ void main() {
676741 tempDirectory.childDirectory ('dirB' ).childFile ('fileB' ).createSync (recursive: true );
677742 },
678743 ),
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- ]),
695744 ]);
696745
697746 macOSUtils.unzip (fileSystem.file ('foo.zip' ), fileSystem.currentDirectory);
698747 expect (fakeProcessManager, hasNoRemainingExpectations);
699748 expect (tempDirectory, isNot (exists));
749+ expect (targetDirectory.childDirectory ('dirA' ).childFile ('fileA' ).existsSync (), isTrue);
750+ expect (targetDirectory.childDirectory ('dirB' ).childFile ('fileB' ).existsSync (), isTrue);
700751 });
701752 });
702753
0 commit comments