@@ -289,19 +289,13 @@ end
289
289
# added to the FileUtils utility functions.
290
290
module FileUtils
291
291
def unarchive ( archive , dest = '.' )
292
- case archive . downcase
293
- when -> ( name ) { name . include? ( '.tar.' ) || name . end_with? ( '.tar' ) }
294
- mkdir_p dest
295
- sh 'tar' , '-vxC' , dest , '-f' , archive , '--no-same-owner' , '--no-same-permissions'
296
- when -> ( name ) { name . end_with? ( '.zip' ) }
297
- if Gem . win_platform?
298
- mkdir_p dest
299
- sh File . absolute_path ( 'System32/tar.exe' , ENV . fetch ( 'SystemRoot' , 'C:/Windows' ) ) , '-vxC' , dest , '-f' , archive
300
- else
301
- sh 'unzip' , '-od' , dest , archive
302
- end
292
+ mkdir_p dest
293
+ if Gem . win_platform?
294
+ sh File . absolute_path ( 'tar.exe' , SassConfig . windows_get_folder_path ( :System ) ) , '-vxC' , dest , '-f' , archive
295
+ elsif archive . downcase . end_with? ( '.zip' )
296
+ sh 'unzip' , '-od' , dest , archive
303
297
else
304
- raise ArgumentError , "Unknown archive format #{ archive } "
298
+ sh 'tar' , '-vxC' , dest , '-f' , archive , '--no-same-owner' , '--no-same-permissions'
305
299
end
306
300
end
307
301
@@ -699,4 +693,19 @@ module SassConfig
699
693
platform
700
694
end
701
695
end
696
+
697
+ def windows_get_folder_path ( folder )
698
+ require 'open3'
699
+
700
+ stdout , stderr , status = Open3 . capture3 ( 'powershell.exe' ,
701
+ '-NoLogo' ,
702
+ '-NoProfile' ,
703
+ '-NonInteractive' ,
704
+ '-Command' ,
705
+ "[Environment]::GetFolderPath('#{ folder } ') | Write-Host -NoNewline" )
706
+
707
+ raise stderr unless status . success?
708
+
709
+ File . absolute_path ( stdout )
710
+ end
702
711
end
0 commit comments