diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 4bba16dc7f398ef2d50222f66a2dac26f821dc2d..80791cd9622f33ba2f8e7b1ba01da2f18d085129 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -418,56 +418,67 @@ public class Compressor { * @throws BundleException FileNotFoundException|IOException. */ private void compressAppMode(Utility utility) throws BundleException { - pathToFile(utility, utility.getJsonPath(), NULL_DIR_NAME, false); + List fileList = new ArrayList<>(); + File appOutputFile = new File(utility.getOutPath().trim()); + String tempPath = appOutputFile.getParentFile().getParent() + File.separator + TEMP_HAP_DIR; + try { + pathToFile(utility, utility.getJsonPath(), NULL_DIR_NAME, false); - if (!utility.getCertificatePath().isEmpty()) { - pathToFile(utility, utility.getCertificatePath(), NULL_DIR_NAME, false); - } + if (!utility.getCertificatePath().isEmpty()) { + pathToFile(utility, utility.getCertificatePath(), NULL_DIR_NAME, false); + } - if (!utility.getSignaturePath().isEmpty()) { - pathToFile(utility, utility.getSignaturePath(), NULL_DIR_NAME, false); - } + if (!utility.getSignaturePath().isEmpty()) { + pathToFile(utility, utility.getSignaturePath(), NULL_DIR_NAME, false); + } - File appOutputFile = new File(utility.getOutPath().trim()); - List fileList = new ArrayList<>(); - String tempPath = appOutputFile.getParentFile().getParent() + File.separator + TEMP_HAP_DIR; - File tempDir = new File(tempPath); - if (!tempDir.exists()) { - tempDir.mkdirs(); - } - for (String hapPathItem : utility.getFormattedHapPathList()) { - File hapFile = new File(hapPathItem.trim()); - String hapTempPath = tempDir + File.separator + hapFile.getName(); - fileList.add(hapTempPath); - try { - compressPackinfoIntoHap(hapPathItem, hapTempPath, utility.getPackInfoPath()); - } catch (IOException e) { - LOG.error("Compressor::compressAppMode compress pack.info into hap failed"); - throw new BundleException("Compressor::compressAppMode compress pack.info into hap failed"); + File tempDir = new File(tempPath); + if (!tempDir.exists()) { + tempDir.mkdirs(); + } + for (String hapPathItem : utility.getFormattedHapPathList()) { + File hapFile = new File(hapPathItem.trim()); + String hapTempPath = tempDir + File.separator + hapFile.getName(); + fileList.add(hapTempPath); + try { + compressPackinfoIntoHap(hapPathItem, hapTempPath, utility.getPackInfoPath()); + } catch (IOException e) { + LOG.error("Compressor::compressAppMode compress pack.info into hap failed"); + throw new BundleException("Compressor::compressAppMode compress pack.info into hap failed"); + } + } + for (String hapPath : fileList) { + pathToFile(utility, hapPath, NULL_DIR_NAME, false); } - } - for (String hapPath : fileList) { - pathToFile(utility, hapPath, NULL_DIR_NAME, false); - } - for (String hapPath : fileList) { - deleteFile(hapPath); - } - deleteFile(tempPath); + for (String hapPath : fileList) { + deleteFile(hapPath); + } + deleteFile(tempPath); - if (!utility.getEntryCardPath().isEmpty()) { - String entryCardPath = ENTRYCARD_NAME + utility.getModuleName() + LINUX_FILE_SEPARATOR - + ENTRYCARD_BASE_NAME + ENTRYCARD_SNAPSHOT_NAME; - for (String entryCardPathItem : utility.getformattedEntryCardPathList()) { - pathToFile(utility, entryCardPathItem, entryCardPath, true); + if (!utility.getEntryCardPath().isEmpty()) { + String entryCardPath = ENTRYCARD_NAME + utility.getModuleName() + LINUX_FILE_SEPARATOR + + ENTRYCARD_BASE_NAME + ENTRYCARD_SNAPSHOT_NAME; + for (String entryCardPathItem : utility.getformattedEntryCardPathList()) { + pathToFile(utility, entryCardPathItem, entryCardPath, true); + } } - } - if (!utility.getPackResPath().isEmpty()) { - pathToFile(utility, utility.getPackResPath(), NULL_DIR_NAME, false); + if (!utility.getPackResPath().isEmpty()) { + pathToFile(utility, utility.getPackResPath(), NULL_DIR_NAME, false); + } + File file = new File(utility.getPackInfoPath()); + compressFile(utility, file, NULL_DIR_NAME, false); + } catch (BundleException e) { + LOG.error("Compressor::compressAppMode compress failed"); + throw new BundleException("Compressor::compressAppMode compress failed"); + } finally { + // delete temp file if compress app failed + for (String hapPath : fileList) { + deleteFile(hapPath); + } + deleteFile(tempPath); } - File file = new File(utility.getPackInfoPath()); - compressFile(utility, file, NULL_DIR_NAME, false); } private void copy(InputStream input, OutputStream output) throws IOException { diff --git a/jar/app_packing_tool.jar b/jar/app_packing_tool.jar index 8a80468f23975c4f845bb56eef740bd80a4722b3..0460b71357cf886f5faffef06decf4cc389356ce 100644 Binary files a/jar/app_packing_tool.jar and b/jar/app_packing_tool.jar differ