Skip to content

Commit f998149

Browse files
authored
Locate bsdtar on windows without environment variable
1 parent 3b3786a commit f998149

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

ext/sass/Rakefile

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,13 @@ end
289289
# added to the FileUtils utility functions.
290290
module FileUtils
291291
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
303297
else
304-
raise ArgumentError, "Unknown archive format #{archive}"
298+
sh 'tar', '-vxC', dest, '-f', archive, '--no-same-owner', '--no-same-permissions'
305299
end
306300
end
307301

@@ -699,4 +693,19 @@ module SassConfig
699693
platform
700694
end
701695
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
702711
end

0 commit comments

Comments
 (0)