@@ -532,8 +532,8 @@ func downloadFile(url, dst string, timeout time.Duration) error {
532532}
533533
534534func fileExists (p string ) bool {
535- _ , err := os .Stat (p )
536- return err == nil
535+ info , err := os .Stat (p )
536+ return err == nil && ! info . IsDir () && info . Size () > 0
537537}
538538
539539// unzipOne extracts a specific file from a zip archive to dstDir
@@ -595,10 +595,11 @@ func untarSelect(tgzPath, dstDir string, names []string) error {
595595 return err
596596 }
597597 base := filepath .Base (hdr .Name )
598- if ! set [base ] || hdr .FileInfo ().IsDir () {
598+ wanted , ok := selectedTarOutputName (hdr .Name , base , set )
599+ if ! ok || hdr .FileInfo ().IsDir () || hdr .Typeflag != tar .TypeReg {
599600 continue
600601 }
601- out := filepath .Join (dstDir , base )
602+ out := filepath .Join (dstDir , wanted )
602603 of , err := os .Create (out )
603604 if err != nil {
604605 return err
@@ -611,7 +612,7 @@ func untarSelect(tgzPath, dstDir string, names []string) error {
611612 if runtime .GOOS != "windows" {
612613 _ = os .Chmod (out , 0o755 )
613614 }
614- delete (set , base )
615+ delete (set , wanted )
615616 if len (set ) == 0 {
616617 break
617618 }
@@ -622,6 +623,35 @@ func untarSelect(tgzPath, dstDir string, names []string) error {
622623 return nil
623624}
624625
626+ func selectedTarOutputName (entryName , base string , set map [string ]bool ) (string , bool ) {
627+ if set [base ] {
628+ return base , true
629+ }
630+
631+ if strings .Contains (entryName , ".dSYM/" ) {
632+ return "" , false
633+ }
634+
635+ for wanted := range set {
636+ if isVersionedSharedLibraryName (wanted , base ) {
637+ return wanted , true
638+ }
639+ }
640+ return "" , false
641+ }
642+
643+ func isVersionedSharedLibraryName (wanted , candidate string ) bool {
644+ if strings .HasSuffix (wanted , ".dylib" ) {
645+ prefix := strings .TrimSuffix (wanted , ".dylib" ) + "."
646+ return strings .HasPrefix (candidate , prefix ) && strings .HasSuffix (candidate , ".dylib" )
647+ }
648+ if strings .HasSuffix (wanted , ".so" ) {
649+ prefix := wanted + "."
650+ return strings .HasPrefix (candidate , prefix )
651+ }
652+ return false
653+ }
654+
625655func keys (m map [string ]bool ) []string {
626656 ks := make ([]string , 0 , len (m ))
627657 for k := range m {
@@ -728,4 +758,4 @@ func (w *wordPiece) tokenizeWord(tok string) []int {
728758 tok = tok [len (cur ):]
729759 }
730760 return out
731- }
761+ }
0 commit comments