* Extract a compressed tar archive * * @param file path to the tar * @param dest destination directory. Optional. * @param flags flags for the tar command to use for extraction. Defaults to 'xz' (extracting gzipped tars). Optional. * @returns path to the destination directory
(file, dest, flags = 'xz')
| 4114 | * @returns path to the destination directory |
| 4115 | */ |
| 4116 | function extractTar(file, dest, flags = 'xz') { |
| 4117 | return __awaiter(this, void 0, void 0, function* () { |
| 4118 | if (!file) { |
| 4119 | throw new Error("parameter 'file' is required"); |
| 4120 | } |
| 4121 | // Create dest |
| 4122 | dest = yield _createExtractFolder(dest); |
| 4123 | // Determine whether GNU tar |
| 4124 | core.debug('Checking tar --version'); |
| 4125 | let versionOutput = ''; |
| 4126 | yield exec_1.exec('tar --version', [], { |
| 4127 | ignoreReturnCode: true, |
| 4128 | silent: true, |
| 4129 | listeners: { |
| 4130 | stdout: (data) => (versionOutput += data.toString()), |
| 4131 | stderr: (data) => (versionOutput += data.toString()) |
| 4132 | } |
| 4133 | }); |
| 4134 | core.debug(versionOutput.trim()); |
| 4135 | const isGnuTar = versionOutput.toUpperCase().includes('GNU TAR'); |
| 4136 | // Initialize args |
| 4137 | let args; |
| 4138 | if (flags instanceof Array) { |
| 4139 | args = flags; |
| 4140 | } |
| 4141 | else { |
| 4142 | args = [flags]; |
| 4143 | } |
| 4144 | if (core.isDebug() && !flags.includes('v')) { |
| 4145 | args.push('-v'); |
| 4146 | } |
| 4147 | let destArg = dest; |
| 4148 | let fileArg = file; |
| 4149 | if (IS_WINDOWS && isGnuTar) { |
| 4150 | args.push('--force-local'); |
| 4151 | destArg = dest.replace(/\\/g, '/'); |
| 4152 | // Technically only the dest needs to have `/` but for aesthetic consistency |
| 4153 | // convert slashes in the file arg too. |
| 4154 | fileArg = file.replace(/\\/g, '/'); |
| 4155 | } |
| 4156 | if (isGnuTar) { |
| 4157 | // Suppress warnings when using GNU tar to extract archives created by BSD tar |
| 4158 | args.push('--warning=no-unknown-keyword'); |
| 4159 | args.push('--overwrite'); |
| 4160 | } |
| 4161 | args.push('-C', destArg, '-f', fileArg); |
| 4162 | yield exec_1.exec(`tar`, args); |
| 4163 | return dest; |
| 4164 | }); |
| 4165 | } |
| 4166 | exports.extractTar = extractTar; |
| 4167 | /** |
| 4168 | * Extract a xar compatible archive |
nothing calls this directly
no test coverage detected
searching dependent graphs…