* Decompress using 7zip
(sourceZip: string, destDir: string)
| 107 | * Decompress using 7zip |
| 108 | */ |
| 109 | async function use7zip(sourceZip: string, destDir: string): Promise<boolean> { |
| 110 | try { |
| 111 | await fs.ensureDir(destDir); |
| 112 | const args = ["x", sourceZip, `-o${destDir}`, "-aoa"]; |
| 113 | logger.info($t("TXT_CODE_35d2ee7a", { command: `${SEVEN_ZIP_PATH} ${args.join(" ")}` })); |
| 114 | |
| 115 | const { stdout, stderr } = await runSpawn(SEVEN_ZIP_PATH, args, { |
| 116 | cwd: path.dirname(sourceZip), |
| 117 | timeout: ZIP_TIMEOUT_SECONDS * 1000 |
| 118 | }); |
| 119 | |
| 120 | const hasErrors = |
| 121 | stdout.includes("ERRORS:") || |
| 122 | stdout.includes("ERROR:") || |
| 123 | stdout.includes("Open Errors:") || |
| 124 | stdout.includes("Missing volume") || |
| 125 | stdout.includes("Data Error") || |
| 126 | stdout.includes("Archives with Errors:"); |
| 127 | |
| 128 | if (hasErrors) { |
| 129 | const errorLines = stdout |
| 130 | .split("\n") |
| 131 | .filter( |
| 132 | (line) => |
| 133 | line.includes("ERROR") || |
| 134 | line.includes("Missing volume") || |
| 135 | line.includes("Data Error") || |
| 136 | line.includes("Open Errors") || |
| 137 | line.includes("Archives with Errors") |
| 138 | ); |
| 139 | |
| 140 | let cleanErrorMsg: string; |
| 141 | if (stdout.includes("Missing volume")) { |
| 142 | const volumeMatch = stdout.match(/Missing volume\s*:\s*([^\s\n]+)/); |
| 143 | if (volumeMatch) { |
| 144 | cleanErrorMsg = $t("TXT_CODE_c0401ba7", { file: volumeMatch[1] }); |
| 145 | } else { |
| 146 | cleanErrorMsg = $t("TXT_CODE_908a4ace"); |
| 147 | } |
| 148 | } else if (stdout.includes("Data Error")) { |
| 149 | cleanErrorMsg = $t("TXT_CODE_b1ef1d4a"); |
| 150 | } else if (stdout.includes("Open Errors")) { |
| 151 | cleanErrorMsg = $t("TXT_CODE_5778848e"); |
| 152 | } else { |
| 153 | const firstError = errorLines[0]?.trim() || $t("TXT_CODE_11ecd5a9"); |
| 154 | cleanErrorMsg = firstError.length > 100 ? firstError.substring(0, 100) + "..." : firstError; |
| 155 | } |
| 156 | |
| 157 | logger.error($t("TXT_CODE_cacd8840", { message: cleanErrorMsg })); |
| 158 | throw new Error($t("TXT_CODE_ec7fc405", { message: cleanErrorMsg })); |
| 159 | } |
| 160 | |
| 161 | if (stderr && stderr.trim()) { |
| 162 | logger.warn($t("TXT_CODE_8a9c6364", { warning: stderr })); |
| 163 | } |
| 164 | |
| 165 | if (stdout.includes("Everything is Ok")) { |
| 166 | logger.info($t("TXT_CODE_e96a91cd")); |
no test coverage detected