@@ -445,13 +445,13 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
445445 full_name = entry . full_name
446446 next unless File . fnmatch pattern , full_name , File ::FNM_DOTMATCH
447447
448- destination = install_location full_name , destination_dir
449-
450- if invalid_windows_filename? ( full_name )
448+ if Gem . win_platform? && invalid_windows_filename? ( full_name )
451449 gem_name = @spec ? @spec . full_name : "unknown"
452450 raise Gem ::Package ::InvalidWindowsFileNameError . new ( full_name , gem_name )
453451 end
454452
453+ destination = install_location full_name , destination_dir
454+
455455 if entry . symlink?
456456 link_target = entry . header . linkname
457457 real_destination = link_target . start_with? ( "/" ) ? link_target : File . expand_path ( link_target , File . dirname ( destination ) )
@@ -480,18 +480,13 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
480480 end
481481
482482 if entry . file?
483- begin
484- File . open ( destination , "wb" ) do |out |
485- copy_stream ( tar . io , out , entry . size )
486- # Flush needs to happen before chmod because there could be data
487- # in the IO buffer that needs to be written, and that could be
488- # written after the chmod (on close) which would mess up the perms
489- out . flush
490- out . chmod file_mode ( entry . header . mode ) & ~File . umask
491- end
492- rescue Errno ::EINVAL
493- gem_name = @spec ? @spec . full_name : "unknown"
494- raise Gem ::Package ::InvalidWindowsFileNameError . new ( full_name , gem_name )
483+ File . open ( destination , "wb" ) do |out |
484+ copy_stream ( tar . io , out , entry . size )
485+ # Flush needs to happen before chmod because there could be data
486+ # in the IO buffer that needs to be written, and that could be
487+ # written after the chmod (on close) which would mess up the perms
488+ out . flush
489+ out . chmod file_mode ( entry . header . mode ) & ~File . umask
495490 end
496491 end
497492
@@ -571,10 +566,7 @@ def normalize_path(pathname) # :nodoc:
571566 # Note: Colons are only valid as drive letter separators (e.g., C:), not in filenames.
572567
573568 def invalid_windows_filename? ( filename ) # :nodoc:
574- return false unless Gem . win_platform?
575-
576- basename = File . basename ( filename )
577- basename . match? ( /[:<>"|?*\\ \x00 -\x1f ]/ )
569+ filename . to_s . split ( "/" ) . any? { |part | part . match? ( /[:<>"|?*\\ \x00 -\x1f ]/ ) }
578570 end
579571
580572 ##
0 commit comments