@@ -441,13 +441,13 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
441441 full_name = entry . full_name
442442 next unless File . fnmatch pattern , full_name , File ::FNM_DOTMATCH
443443
444- destination = install_location full_name , destination_dir
445-
446- if invalid_windows_filename? ( full_name )
444+ if Gem . win_platform? && invalid_windows_filename? ( full_name )
447445 gem_name = @spec ? @spec . full_name : "unknown"
448446 raise Gem ::Package ::InvalidWindowsFileNameError . new ( full_name , gem_name )
449447 end
450448
449+ destination = install_location full_name , destination_dir
450+
451451 if entry . symlink?
452452 link_target = entry . header . linkname
453453 real_destination = link_target . start_with? ( "/" ) ? link_target : File . expand_path ( link_target , File . dirname ( destination ) )
@@ -471,18 +471,13 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
471471 end
472472
473473 if entry . file?
474- begin
475- File . open ( destination , "wb" ) do |out |
476- copy_stream ( tar . io , out , entry . size )
477- # Flush needs to happen before chmod because there could be data
478- # in the IO buffer that needs to be written, and that could be
479- # written after the chmod (on close) which would mess up the perms
480- out . flush
481- out . chmod file_mode ( entry . header . mode ) & ~File . umask
482- end
483- rescue Errno ::EINVAL
484- gem_name = @spec ? @spec . full_name : "unknown"
485- raise Gem ::Package ::InvalidWindowsFileNameError . new ( full_name , gem_name )
474+ File . open ( destination , "wb" ) do |out |
475+ copy_stream ( tar . io , out , entry . size )
476+ # Flush needs to happen before chmod because there could be data
477+ # in the IO buffer that needs to be written, and that could be
478+ # written after the chmod (on close) which would mess up the perms
479+ out . flush
480+ out . chmod file_mode ( entry . header . mode ) & ~File . umask
486481 end
487482 end
488483
@@ -562,10 +557,7 @@ def normalize_path(pathname) # :nodoc:
562557 # Note: Colons are only valid as drive letter separators (e.g., C:), not in filenames.
563558
564559 def invalid_windows_filename? ( filename ) # :nodoc:
565- return false unless Gem . win_platform?
566-
567- basename = File . basename ( filename )
568- basename . match? ( /[:<>"|?*\\ \x00 -\x1f ]/ )
560+ filename . to_s . split ( "/" ) . any? { |part | part . match? ( /[:<>"|?*\\ \x00 -\x1f ]/ ) }
569561 end
570562
571563 ##
0 commit comments