MCPcopy Create free account
hub / github.com/Azure/powershell / extractZipWin

Function extractZipWin

lib/index.js:4220–4270  ·  view source on GitHub ↗
(file, dest)

Source from the content-addressed store, hash-verified

4218}
4219exports.extractZip = extractZip;
4220function extractZipWin(file, dest) {
4221 return __awaiter(this, void 0, void 0, function* () {
4222 // build the powershell command
4223 const escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, ''); // double-up single quotes, remove double quotes and newlines
4224 const escapedDest = dest.replace(/'/g, "''").replace(/"|\n|\r/g, '');
4225 const pwshPath = yield io.which('pwsh', false);
4226 //To match the file overwrite behavior on nix systems, we use the overwrite = true flag for ExtractToDirectory
4227 //and the -Force flag for Expand-Archive as a fallback
4228 if (pwshPath) {
4229 //attempt to use pwsh with ExtractToDirectory, if this fails attempt Expand-Archive
4230 const pwshCommand = [
4231 `$ErrorActionPreference = 'Stop' ;`,
4232 `try { Add-Type -AssemblyName System.IO.Compression.ZipFile } catch { } ;`,
4233 `try { [System.IO.Compression.ZipFile]::ExtractToDirectory('${escapedFile}', '${escapedDest}', $true) }`,
4234 `catch { if (($_.Exception.GetType().FullName -eq 'System.Management.Automation.MethodException') -or ($_.Exception.GetType().FullName -eq 'System.Management.Automation.RuntimeException') ){ Expand-Archive -LiteralPath '${escapedFile}' -DestinationPath '${escapedDest}' -Force } else { throw $_ } } ;`
4235 ].join(' ');
4236 const args = [
4237 '-NoLogo',
4238 '-NoProfile',
4239 '-NonInteractive',
4240 '-ExecutionPolicy',
4241 'Unrestricted',
4242 '-Command',
4243 pwshCommand
4244 ];
4245 core.debug(`Using pwsh at path: ${pwshPath}`);
4246 yield exec_1.exec(`"${pwshPath}"`, args);
4247 }
4248 else {
4249 const powershellCommand = [
4250 `$ErrorActionPreference = 'Stop' ;`,
4251 `try { Add-Type -AssemblyName System.IO.Compression.FileSystem } catch { } ;`,
4252 `if ((Get-Command -Name Expand-Archive -Module Microsoft.PowerShell.Archive -ErrorAction Ignore)) { Expand-Archive -LiteralPath '${escapedFile}' -DestinationPath '${escapedDest}' -Force }`,
4253 `else {[System.IO.Compression.ZipFile]::ExtractToDirectory('${escapedFile}', '${escapedDest}', $true) }`
4254 ].join(' ');
4255 const args = [
4256 '-NoLogo',
4257 '-Sta',
4258 '-NoProfile',
4259 '-NonInteractive',
4260 '-ExecutionPolicy',
4261 'Unrestricted',
4262 '-Command',
4263 powershellCommand
4264 ];
4265 const powershellPath = yield io.which('powershell', true);
4266 core.debug(`Using powershell at path: ${powershellPath}`);
4267 yield exec_1.exec(`"${powershellPath}"`, args);
4268 }
4269 });
4270}
4271function extractZipNix(file, dest) {
4272 return __awaiter(this, void 0, void 0, function* () {
4273 const unzipPath = yield io.which('unzip', true);

Callers 1

extractZipFunction · 0.85

Calls 1

execMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…