From d8568308423f7d4673194e687a561eb3d8eae89a Mon Sep 17 00:00:00 2001 From: "yongsung1.kim" Date: Fri, 28 Mar 2014 19:11:45 +0900 Subject: [PATCH] [INST] Installmanager can support SDK small patch. Change-Id: I5e044b85aa87d65d8fe5a44cc861ced088f19b41 Signed-off-by: yongsung1.kim --- .../tizen/installmanager/cli/CliUnzipImage.java | 75 ++++-- .../installmanager/cli/InstallManagerNoUI.java | 17 +- .../core/InstallManagerConstants.java | 14 + .../org/tizen/installmanager/core/Installer.java | 6 +- .../src/org/tizen/installmanager/core/Options.java | 55 +++- .../src/org/tizen/installmanager/lib/Patch.java | 299 +++++++++++++++++++++ .../installmanager/pkg/lib/PackageManager.java | 13 +- .../installmanager/pkg/lib/PropertyParser.java | 2 +- .../installmanager/ui/InstallManagerWindow.java | 12 + .../org/tizen/installmanager/util/PathUtil.java | 74 ++++- 10 files changed, 518 insertions(+), 49 deletions(-) create mode 100644 InstallManager_java/src/org/tizen/installmanager/lib/Patch.java diff --git a/InstallManager_java/src/org/tizen/installmanager/cli/CliUnzipImage.java b/InstallManager_java/src/org/tizen/installmanager/cli/CliUnzipImage.java index 5f27027..8a106f9 100644 --- a/InstallManager_java/src/org/tizen/installmanager/cli/CliUnzipImage.java +++ b/InstallManager_java/src/org/tizen/installmanager/cli/CliUnzipImage.java @@ -40,8 +40,10 @@ import java.util.zip.ZipInputStream; import org.tizen.installmanager.core.Config; import org.tizen.installmanager.core.IMFatalException; +import org.tizen.installmanager.core.InstallManagerConstants; import org.tizen.installmanager.lib.Log; import org.tizen.installmanager.lib.ErrorController.ErrorCode; +import org.tizen.installmanager.lib.Registry; import org.tizen.installmanager.pkg.lib.PackageManager; import org.tizen.installmanager.util.PathUtil; import org.tizen.installmanager.util.ResourceHandler; @@ -58,9 +60,10 @@ public class CliUnzipImage { final static int BUF_SIZE = 65536; final static int EMPTY_SIZE = 0; + public enum UNZIP_FILE_STYLE {IMAGE, PATCH}; public enum UNZIP_RESULT {FAIL, ERROR, SUCCESS}; - protected CliUnzipImage(File file) { + public CliUnzipImage(File file) { imageFile = file; totalWork = getEntryCount(file); } @@ -68,20 +71,33 @@ public class CliUnzipImage { /** * Unzip SDK ImageFile. * - * @param imageFile SDK Image File. + * @param imageFile SDK Image or Patch File. * @return if success to unzip is 1, not -1 or 0. */ - public String unzipSDKImageFile(final File imageFile) { - if (!validation(imageFile.getAbsolutePath())) { - Log.err("This SDK image is corrupted or broken."); - System.out.println("SDK image file does not have a package list file."); - throw new IMFatalException("SDK image file does not have a package list file."); - } + public String unzipSDKImageFile(final File imageFile, UNZIP_FILE_STYLE style) { + String unzipTargetDir = null; - Log.log("Start to unzip SDK Image File. => " + imageFile.getAbsolutePath()); - - String unzipTargetDir = PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY, - Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME, imageFile.getName()); + if (style == UNZIP_FILE_STYLE.IMAGE) { + if (!validation(imageFile.getAbsolutePath(), style)) { + Log.err("This SDK image is corrupted or broken."); + System.out.println("SDK image file does not have a package list file."); + throw new IMFatalException("SDK image file does not have a package list file."); + } + Log.log("Start to unzip SDK Image File. => " + imageFile.getAbsolutePath()); + + unzipTargetDir = PathUtil.get(Config.INSTALL_MANAGER_TEMP_DIRECTORY, + Config.INSTALL_MANAGER_DOWNLOAD_DIRECTORY_NAME, imageFile.getName()); + } else if (style == UNZIP_FILE_STYLE.PATCH) { + if (!validation(imageFile.getAbsolutePath(), style)) { + Log.err("This SDK patch is corrupted or broken."); + System.out.println("SDK patch file does not have a pkginfo.manifest file."); + throw new IMFatalException("SDK patch file does not have a pkginfo.manifest file."); + } + System.out.println("*** Extracting ***"); + Log.log("Start to unzip SDK Patch File. => " + imageFile.getAbsolutePath()); + + unzipTargetDir = PathUtil.get(Registry.getInstalledPath(), InstallManagerConstants.SDK_PATCH_TEMP_NAME); + } Log.log("unzip to " + unzipTargetDir); @@ -129,6 +145,7 @@ public class CliUnzipImage { ZipInputStream zis = null; ZipEntry zipEntry = null; int work = 1; + int cnt = 0; try { fis = new FileInputStream(imageFile); @@ -144,11 +161,20 @@ public class CliUnzipImage { } } else { // File case // Make parent directory - File parent = new File(targetFile.getParent()); - parent.mkdir(); +// File parent = new File(targetFile.getParent()); + File parent = PathUtil.makeParent(targetFile.getAbsolutePath()); + + if (!parent.getAbsolutePath().equalsIgnoreCase(sdkTempDir)) { + cnt = PathUtil.getParentCnt(fileNameToUnzip); + } + if (0 > unzipEntry(zis, targetFile)) { System.out.println(zipEntry.getName() + " ..... done."); - work++; + if (cnt == 0) { + work++; + } else { + work = work + cnt; + } } else { System.out.println(zipEntry.getName() + " ..... fail."); } @@ -157,9 +183,9 @@ public class CliUnzipImage { if (work == totalWork) { setUnzipResult(UNZIP_RESULT.SUCCESS); - Log.log("Success to extract SDK image properly."); + Log.log("Success to extract SDK image or patch properly."); } else { - Log.err("InstallManager cannot extract SDK image properly. (Total entry : " + totalWork + Log.err("InstallManager cannot extract SDK image or patch properly. (Total entry : " + totalWork + " Extracted entry : " + work); setUnzipResult(UNZIP_RESULT.ERROR); } @@ -240,7 +266,7 @@ public class CliUnzipImage { } @SuppressWarnings("unused") - private boolean validation(String strDir) { + private boolean validation(String strDir, UNZIP_FILE_STYLE style) { ZipFile zipFile = null; ZipEntry entry = null; @@ -252,10 +278,15 @@ public class CliUnzipImage { } if (zipFile != null) { - String packageList = PackageManager.getInstance().getPackageListFileName(); - Log.log("This platform must have package list file as '" + packageList + "'"); - - entry = zipFile.getEntry(packageList); + if (style == UNZIP_FILE_STYLE.IMAGE) { + String packageList = PackageManager.getInstance().getPackageListFileName(); + Log.log("This platform must have package list file as '" + packageList + "'"); + entry = zipFile.getEntry(packageList); + } else if (style == UNZIP_FILE_STYLE.PATCH) { + String scriptFile = InstallManagerConstants.SDK_PATCH_PKG_INFO; + Log.log("Patch must have pkginfo.manifest file."); + entry = zipFile.getEntry(scriptFile); + } try { zipFile.close(); diff --git a/InstallManager_java/src/org/tizen/installmanager/cli/InstallManagerNoUI.java b/InstallManager_java/src/org/tizen/installmanager/cli/InstallManagerNoUI.java index e229764..915dd4b 100644 --- a/InstallManager_java/src/org/tizen/installmanager/cli/InstallManagerNoUI.java +++ b/InstallManager_java/src/org/tizen/installmanager/cli/InstallManagerNoUI.java @@ -32,6 +32,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import org.tizen.installmanager.cli.CliUnzipImage.UNZIP_FILE_STYLE; import org.tizen.installmanager.cli.CliUnzipImage.UNZIP_RESULT; import org.tizen.installmanager.core.Config; import org.tizen.installmanager.core.IMExitException; @@ -40,6 +41,7 @@ import org.tizen.installmanager.core.InstallManager; import org.tizen.installmanager.core.Options; import org.tizen.installmanager.core.Config.ServerType; import org.tizen.installmanager.lib.Log; +import org.tizen.installmanager.lib.Patch; import org.tizen.installmanager.lib.Registry; import org.tizen.installmanager.ui.InstallManagerWindow; @@ -114,7 +116,7 @@ public class InstallManagerNoUI { String imgFilePath = CliInstall.getReformedPath(Options.imageFilePath, false); File imageFile = new File(imgFilePath); CliUnzipImage cui = new CliUnzipImage(imageFile); - String unzipTargetDir = cui.unzipSDKImageFile(imageFile); + String unzipTargetDir = cui.unzipSDKImageFile(imageFile, UNZIP_FILE_STYLE.IMAGE); if (cui.getUnzipResult() == UNZIP_RESULT.SUCCESS) { Options.repository = unzipTargetDir; @@ -255,4 +257,17 @@ public class InstallManagerNoUI { public static void cliShowPackageList() { CliShowInformation.showRepoPackages(); } + + public static void cliSDKPatch() { + System.out.println("****************************************"); + System.out.println("*********** Start SDK patch ************"); + System.out.println("****************************************"); + + Patch patch = new Patch(); + if (patch.patchSDK()) { + System.out.println("Success to SDK patch process."); + } else { + System.out.println("Fail to SDK patch process."); + } + } } diff --git a/InstallManager_java/src/org/tizen/installmanager/core/InstallManagerConstants.java b/InstallManager_java/src/org/tizen/installmanager/core/InstallManagerConstants.java index c87f6cd..cda0b7c 100644 --- a/InstallManager_java/src/org/tizen/installmanager/core/InstallManagerConstants.java +++ b/InstallManager_java/src/org/tizen/installmanager/core/InstallManagerConstants.java @@ -34,6 +34,10 @@ public class InstallManagerConstants { final static public String SDK_INSTALLED_PACKAGE_LIST_FILE = "installedpackage.list"; final static public String SDK_INSTALLED_PACKAGE_LIST_PATH = PathUtil.get(SDK_CONFIGURATION_DIR, SDK_INSTALLED_PACKAGE_LIST_FILE); + final static public String SDK_PATCH_SCRIPT = getPatchScript(); + final static public String SDK_PATCH_TEMP_NAME = "patchTemp"; + final static public String SDK_PATCH_PKG_INFO = "pkginfo.manifest"; + //test file final static public String SDK_TEST_DIR_NAME = "test"; // final static public String SDK_INSTALLMANAGER_TEST_RESULT_DIR_PATH = PathUtil.get(SDK_DATA_PATH, SDK_TEST_DIR_NAME, INSTALLMANAGER_DIRECTORY_NAME); @@ -94,4 +98,14 @@ public class InstallManagerConstants { throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM); } } + + static String getPatchScript() { + if (Platform.isLinux() || Platform.isMacOS()) { + return "patch.sh"; + } else if (Platform.isWindows()) { + return "patch.bat"; + } else { + throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM); + } + } } diff --git a/InstallManager_java/src/org/tizen/installmanager/core/Installer.java b/InstallManager_java/src/org/tizen/installmanager/core/Installer.java index 87d9b6f..c53e396 100644 --- a/InstallManager_java/src/org/tizen/installmanager/core/Installer.java +++ b/InstallManager_java/src/org/tizen/installmanager/core/Installer.java @@ -263,7 +263,7 @@ public class Installer { * * @return Environment variables map */ - private Map setEnvironmentVariable() { + public Map setEnvironmentVariable() { HashMap env = new HashMap(); env.put("INSTALLED_PATH", Registry.getInstalledPath()); @@ -341,12 +341,12 @@ public class Installer { for (int i = 0; i < fromList.length; i++) { boolean ret = false; if (Platform.isLinux()) { - ret = PathUtil.copyHardLink(fromList[i], toFile); + ret = PathUtil.copyHardLink(fromList[i], toFile, false); } else if (Platform.isWindows()) { ret = PathUtil.move(fromList[i], new File(toFile, fromList[i].getName())); } else if (Platform.isMacOS()) { - ret = PathUtil.copyHardLink(fromList[i], toFile); + ret = PathUtil.copyHardLink(fromList[i], toFile, false); } else { throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM); } diff --git a/InstallManager_java/src/org/tizen/installmanager/core/Options.java b/InstallManager_java/src/org/tizen/installmanager/core/Options.java index adcc94d..949d08d 100644 --- a/InstallManager_java/src/org/tizen/installmanager/core/Options.java +++ b/InstallManager_java/src/org/tizen/installmanager/core/Options.java @@ -37,6 +37,7 @@ import org.tizen.installmanager.core.Config.ServerType; import org.tizen.installmanager.lib.Log; import org.tizen.installmanager.lib.Platform; import org.tizen.installmanager.lib.ErrorController.ErrorCode; +import org.tizen.installmanager.lib.Registry; /** * This class represents options from command line arguments. @@ -190,6 +191,12 @@ public class Options { public static String executablePath = null; /** + * SDK patch + */ + public static boolean doSDKPatch = false; + public static String SDKPatchPath = null; + + /** * Parses command line arguments and sets corresponding options. * @param args command line arguments */ @@ -250,6 +257,24 @@ public class Options { throw new IMFatalException(ErrorCode.WRONG_OPTION); } break; + } else if (arg.equalsIgnoreCase("-patch")) { + if (!canSDKPatch()) { + Log.err("Cannot find installed SDK. The SDK must be installed before patching."); + System.out.println("Cannot find installed SDK. The SDK must be installed before patching."); + throw new IMFatalException(ErrorCode.WRONG_OPTION); + } else { + if (iter.hasNext()) { + doSDKPatch = true; + workCliOptions(args); + } + + if (SDKPatchPath == null) { + Log.err("Cannot find SDK patch file path."); + System.out.println("Cannot find SDK patch file path. Please check your '-f' options."); + throw new IMFatalException(ErrorCode.WRONG_OPTION); + } + } + break; } else if (arg.equalsIgnoreCase("-repoinfo")) { if (iter.hasNext()) { doShowDistListNoUI = true; @@ -409,8 +434,9 @@ public class Options { for (String t : args) { if (!t.equalsIgnoreCase("-install") && !t.equalsIgnoreCase("-remove") - && !t.equalsIgnoreCase("-download")) { - argArray.add(t); + && !t.equalsIgnoreCase("-download") + && !t.equalsIgnoreCase("-patch")) { + argArray.add(t); } } @@ -445,12 +471,17 @@ public class Options { argIter = argArray.iterator(); while (argIter.hasNext()) { if (argIter.next().equalsIgnoreCase("-f")) { - argIter.remove(); - imageFilePath = argIter.next(); - isNetwork = false; - serverType = ServerType.LOCAL; - argIter.remove(); - exclusiveOptions("-d", argArray); + if (doInstallNoUI) { + argIter.remove(); + imageFilePath = argIter.next(); + isNetwork = false; + serverType = ServerType.LOCAL; + argIter.remove(); + exclusiveOptions("-d", argArray); + } else if (doSDKPatch) { + SDKPatchPath = argIter.next(); + argIter.remove(); + } } } @@ -596,4 +627,12 @@ public class Options { } } } + + private static boolean canSDKPatch() { + if (Registry.isInstalled()) { + return true; + } else { + return false; + } + } } diff --git a/InstallManager_java/src/org/tizen/installmanager/lib/Patch.java b/InstallManager_java/src/org/tizen/installmanager/lib/Patch.java new file mode 100644 index 0000000..6247c42 --- /dev/null +++ b/InstallManager_java/src/org/tizen/installmanager/lib/Patch.java @@ -0,0 +1,299 @@ +/* + * InstallManager + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Donghee Yang + * Shihyun Kim + * Yongsung kim + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.installmanager.lib; + +import java.io.File; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.tizen.installmanager.cli.CliUnzipImage; +import org.tizen.installmanager.cli.CliUnzipImage.UNZIP_FILE_STYLE; +import org.tizen.installmanager.core.Config; +import org.tizen.installmanager.core.IMFatalException; +import org.tizen.installmanager.core.InstallManager; +import org.tizen.installmanager.core.Installer; +import org.tizen.installmanager.core.Options; +import org.tizen.installmanager.lib.ErrorController.ErrorCode; +import org.tizen.installmanager.lib.ErrorController.InfoCode; +import org.tizen.installmanager.pkg.lib.PackageManager; +import org.tizen.installmanager.pkg.lib.PropertyParser; +import org.tizen.installmanager.pkg.model.Package; +import org.tizen.installmanager.pkg.model.Properties; +import org.tizen.installmanager.pkg.model.Property; +import org.tizen.installmanager.pkg.model.PropertySection; +import org.tizen.installmanager.util.IMShellCommandFail; +import org.tizen.installmanager.util.PathUtil; +import org.tizen.installmanager.util.ShellUtil; + +/** + * This class supports SDK patch. + * @author Yongsung Kim + * + */ +public class Patch { + public static final String PATCH_SCRIPT_LINUX = "patch.sh"; + public static final String PATCH_SCRIPT_WINDOWS = "patch.bat"; + public static final String PATCH_PKG_INFO = "pkginfo.manifest"; + + private String patchPath = null; + private Package patchPackage = null; + + public Patch() { + patchPath = Options.SDKPatchPath; + } + + public boolean patchSDK() { + File patchFile = new File(patchPath); + CliUnzipImage cui = new CliUnzipImage(patchFile); + String patchTempPath = cui.unzipSDKImageFile(patchFile, UNZIP_FILE_STYLE.PATCH); + + System.out.println("*** Patch processing ***"); + boolean move = moveToTargetDirectoryFromTempDirectory(patchTempPath, Registry.getInstalledPath()); + + if (move) { + setPatchPackageInfo(patchTempPath); + executePatchScript(patchTempPath); + removePatchTemp(patchTempPath); + } else { + return false; + } + + if (setInstalledVersionUp()) { + return true; + } else { + return false; + } + } + + private void setPatchPackageInfo(String patchTempDir) { + List propertySections = null; + PropertyParser parser = new PropertyParser(); + propertySections = parser.readFromFile(PathUtil.get(patchTempDir, PATCH_PKG_INFO)); + + PropertySection section = new PropertySection(); + for (PropertySection sect : propertySections) { + section = sect; + } + + String repo = null; + Collection repos = Config.getInstance().getSDKPackageServerList(); + + for (String tmp : repos) { + repo = tmp; + } + + patchPackage = new Package(section.getProperties(), repo); + } + + public Package getPatchPackage() { + return patchPackage; + } + + private boolean executePatchScript(String patchTempDir) { + File scriptFile = getPatchScript(patchTempDir); + if (scriptFile.exists()) { + Log.log("Execute patch script"); + + try { + return executeScript(scriptFile); + } catch (IMShellCommandFail e) { + Log.ExceptionLog(e); + throw new IMFatalException( + ErrorController + .getMessage(ErrorCode.INSTALL_SCRIPT_FATAL_ERROR) + + " (" + patchPackage.getPackageName() + " package)"); + } + } else { + Log.log(patchPackage.getPackageName() + " does not have patch script"); + } + return true; + } + + private File getPatchScript(String patchTempDir) { + File scriptFile = null; + + if (Platform.isUbuntu() || Platform.isMacOS()) { + scriptFile = new File(PathUtil.get(patchTempDir, PATCH_SCRIPT_LINUX)); + } else if (Platform.isWindows()) { + scriptFile = new File(PathUtil.get(patchTempDir, PATCH_SCRIPT_WINDOWS)); + } else { + Log.err("Platform not supported."); + throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM); + } + + return scriptFile; + } + + /** + * Executes the file with default environment variables + * + * @param scriptFile + * @return true if success + * @throws IMShellCommandFail + */ + public boolean executeScript(File scriptFile) throws IMShellCommandFail { + scriptFile.setExecutable(true); + Installer installer = new Installer(); + Map env = installer.setEnvironmentVariable(); // except sdk data path. + + String command = ShellUtil.addInterpreter(scriptFile.getAbsolutePath()); + + String current = PathUtil.getCurrentDir(); + Log.log("Current working directory. => " + current); + int exitCode = ShellUtil.execute(command, env, new File(current), + new LoggerShellParser()); + + // check exit code + if (exitCode == 0) { + System.out.println("Execute patch script ..... done"); + return true; + } else if (exitCode == 1 || exitCode == 2) { + Log.err("Exit code => " + Integer.toString(exitCode)); + System.out.println("Execute patch script ..... fail (exit code : " + exitCode + ")"); + return false; + } else if (exitCode == 99) { + ErrorController.setInfoCode(InfoCode.RESTART_THE_COMPUTER); + Log.log("Set restart message."); + return true; + } else { + System.out.println("Execute patch script ..... fail (exit code : " + exitCode + ")"); + Log.err("patch script error => " + scriptFile.getAbsolutePath()); + Log.err("Exit code => " + Integer.toString(exitCode)); + throw new IMFatalException(ErrorController.getMessage(ErrorCode.SCRIPT_FATAL_ERROR) + + " (" + patchPackage.getPackageName() + " package)"); + } + } + + private void removePatchTemp(String patchTempDir) { + if (PathUtil.remove(patchTempDir)) { + Log.log("Success to remove patch temporary directory. ==> " + patchTempDir); + System.out.println("Success to remove patch temporary directory."); + } else { + Log.err("Fail to remove patch temporary directory. ==> " + patchTempDir); + System.out.println("Fail to remove patch temporary directory."); + } + + } + + private boolean moveToTargetDirectoryFromTempDirectory(String tempDir, + String targetDir) { + Log.log("Move temp to target"); + File fromFile = new File(tempDir + File.separator + + Config.DATA_DIRECTORY); + if (!fromFile.exists()) { + Log.err("Data directory is not exist in package."); + return true; + } + File toFile = new File(targetDir); + + File[] fromList = fromFile.listFiles(); + + if (fromList == null) { + return false; + } + + for (int i = 0; i < fromList.length; i++) { + boolean ret = false; + if (Platform.isLinux()) { + ret = PathUtil.copyHardLink(fromList[i], toFile, true); + } else if (Platform.isWindows()) { + ret = PathUtil.move(fromList[i], + new File(toFile, fromList[i].getName())); + } else if (Platform.isMacOS()) { + ret = PathUtil.copyHardLink(fromList[i], toFile, true); + } else { + throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM); + } + if (!ret) { + return false; + } + } + return true; + } + + private boolean setInstalledVersionUp() { + // Remove patch package property from installed packages properties. + PackageManager pm = InstallManager.getInstance().getPackageManager(); + Package installedPkg = pm.getInstalledPackageByName(patchPackage.getPackageName()); + PropertySection iSection = new PropertySection(); + Properties installedPkgProps = (Properties) installedPkg.getProperties(); + iSection.setProperties(installedPkgProps); + + String filePath = PathUtil.get( + PathUtil.getFromInstalledPath(Config.INFO_DIRECTORY), + Config.INSTALLED_PACKAGE_LIST_FILE_NAME); + + List sectionsInstalled = null; + List sectionsInstalledClone = null; + + PropertyParser parser = new PropertyParser(); + sectionsInstalled = parser.readFromFile(filePath); + sectionsInstalledClone = parser.readFromFile(filePath); + + int cnt = 0; + + // Filtering patch package from installed packages. + for (PropertySection p : sectionsInstalledClone) { + String m = p.getProperties().get(0).getValue(); + String k = iSection.getProperties().get(0).getValue(); + cnt ++; + if (m.equalsIgnoreCase(k)) { + int index = cnt - 1; + sectionsInstalled.remove(index); + } + } + + // Replace version from installed to patch. + for (Property prop : installedPkgProps) { + if (prop.getName().equalsIgnoreCase(Package.FIELD_VERSION)) { + prop.setValue(patchPackage.getVersion().toString()); + } + } + + iSection.setProperties(installedPkgProps); + if (!sectionsInstalled.add(iSection)) { + System.out.println("Cannot update patch package version. (from : " + installedPkg.getVersion() + + " to : " + patchPackage.getVersion()); + Log.err("Cannot update patch package version. (from : " + installedPkg.getVersion() + + " to : " + patchPackage.getVersion()); + return false; + } else { + System.out.println("Success to update patch package version. (from : " + installedPkg.getVersion() + + " to : " + patchPackage.getVersion()); + Log.log("Success to update patch package version. (from : " + installedPkg.getVersion() + + " to : " + patchPackage.getVersion()); + } + + // Write the new installedpackage.list + parser.writeToFile(sectionsInstalled, filePath); + System.out.println("Write a updated installedpackage.list file ... done"); + + return true; + } +} diff --git a/InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java b/InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java index 09f0a81..a590a57 100644 --- a/InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java +++ b/InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java @@ -423,7 +423,7 @@ public abstract class PackageManager { * @param destPackages It is set of packages. * @param repoToSectionsMap It is added to destPackages */ - private boolean setPackages(PackageSet destPackages, Map> repoToSectionsMap, boolean isExtensionPackage) { + public boolean setPackages(PackageSet destPackages, Map> repoToSectionsMap, boolean isExtensionPackage) { if (destPackages == null) { destPackages = new PackageSet(); } @@ -1766,6 +1766,17 @@ public abstract class PackageManager { return pSections; } + public PropertySection saveProperySectionsFromPackages(Package pkg) { + PropertySection pSection = null; + Properties properties = null; + + properties = (Properties)pkg.getProperties(); + pSection = new PropertySection(); + pSection.setProperties(properties); + + return pSection; + } + /** * Check the repository change. * @return diff --git a/InstallManager_java/src/org/tizen/installmanager/pkg/lib/PropertyParser.java b/InstallManager_java/src/org/tizen/installmanager/pkg/lib/PropertyParser.java index 536bf00..047f4fc 100644 --- a/InstallManager_java/src/org/tizen/installmanager/pkg/lib/PropertyParser.java +++ b/InstallManager_java/src/org/tizen/installmanager/pkg/lib/PropertyParser.java @@ -119,7 +119,7 @@ public class PropertyParser { } //end of file. - if (sReadData == null) { + if (sReadData == null || sReadData.startsWith("#")) { if (pFieldList.size() > 0) { pSection = new PropertySection(); pSection.setProperties(pFieldList); diff --git a/InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java b/InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java index 42212f8..0ac06fc 100644 --- a/InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java +++ b/InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java @@ -63,11 +63,13 @@ import org.tizen.installmanager.core.Config; import org.tizen.installmanager.core.IMExitException; import org.tizen.installmanager.core.IMFatalException; import org.tizen.installmanager.core.InstallManager; +import org.tizen.installmanager.core.InstallManagerConstants; import org.tizen.installmanager.core.Options; import org.tizen.installmanager.core.Performance; import org.tizen.installmanager.lib.ErrorController; import org.tizen.installmanager.lib.IMError; import org.tizen.installmanager.lib.Log; +import org.tizen.installmanager.lib.Patch; import org.tizen.installmanager.lib.Platform; import org.tizen.installmanager.lib.ProgramController; import org.tizen.installmanager.lib.Registry; @@ -926,6 +928,9 @@ public class InstallManagerWindow extends ApplicationWindow { InstallManagerNoUI.cliShowPackageList(); } else if (Options.doShowSDKInstallStatus) { InstallManagerNoUI.cliShowInstallInformation(); + } else if (Options.doSDKPatch) { + InstallManagerNoUI.cliSDKPatch(); + System.exit(0); } else { window.open(); if (Display.getCurrent() != null @@ -944,6 +949,13 @@ public class InstallManagerWindow extends ApplicationWindow { Log.err("Unexpected error occurred"); Log.ExceptionLog(e); + if (Options.doSDKPatch) { + System.out.println("Fail to SDK patch process."); + PathUtil.remove(PathUtil.get( + Registry.getInstalledPath(), InstallManagerConstants.SDK_PATCH_TEMP_NAME)); + System.exit(0); + } + if (Options.doInstallNoUI || Options.doRemoveNoUI) { PathUtil.remove(Registry.REGISTRY_FILE_PATH); PathUtil.remove(Registry.MULTI_SDK_FILE_PATH); diff --git a/InstallManager_java/src/org/tizen/installmanager/util/PathUtil.java b/InstallManager_java/src/org/tizen/installmanager/util/PathUtil.java index 9b7b46c..15b5c9e 100644 --- a/InstallManager_java/src/org/tizen/installmanager/util/PathUtil.java +++ b/InstallManager_java/src/org/tizen/installmanager/util/PathUtil.java @@ -39,6 +39,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URL; +import java.util.StringTokenizer; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; @@ -168,11 +169,15 @@ public class PathUtil { * @param toFile * @return */ - public static boolean copyHardLink(File fromFile, File toFile) { + public static boolean copyHardLink(File fromFile, File toFile, boolean overwrite) { Log.log("Copy from " + fromFile + " to " + toFile); + if (overwrite) { + Log.log("Set overwrite flag."); + } + String fromPath = fromFile.getAbsolutePath(); - String[] command = getCopyShellCommand(fromPath, toFile.getAbsolutePath()); + String[] command = getCopyShellCommand(fromPath, toFile.getAbsolutePath(), overwrite); try { ShellUtil.execute(command); } catch (IMShellCommandFail e) { @@ -184,17 +189,31 @@ public class PathUtil { return true; } - private static String[] getCopyShellCommand(String fromPath, String toPath) { - if (Platform.CURRENT_PLATFORM == Platform.LINUX_32 - || Platform.CURRENT_PLATFORM == Platform.LINUX_64) { - String command[] = {"cp", "-rl", fromPath, toPath}; - return command; - } else if (Platform.CURRENT_PLATFORM == Platform.MACOS_64) { - String command[] = {"cp", "-a", fromPath, toPath}; - return command; + private static String[] getCopyShellCommand(String fromPath, String toPath, boolean overwrite) { + if (overwrite) { + if (Platform.CURRENT_PLATFORM == Platform.LINUX_32 + || Platform.CURRENT_PLATFORM == Platform.LINUX_64) { + String command[] = {"cp", "-rlf", fromPath, toPath}; + return command; + } else if (Platform.CURRENT_PLATFORM == Platform.MACOS_64) { + String command[] = {"cp", "-af", fromPath, toPath}; + return command; + } else { + return null; + } } else { - return null; + if (Platform.CURRENT_PLATFORM == Platform.LINUX_32 + || Platform.CURRENT_PLATFORM == Platform.LINUX_64) { + String command[] = {"cp", "-rl", fromPath, toPath}; + return command; + } else if (Platform.CURRENT_PLATFORM == Platform.MACOS_64) { + String command[] = {"cp", "-a", fromPath, toPath}; + return command; + } else { + return null; + } } + } //Copy file @@ -582,6 +601,35 @@ public class PathUtil { return file; } + public static File makeParent(String filePath) throws IOException{ + File file = new File(filePath); + if (file.exists()) { + Log.log("<" + file + "> exists already. it will be removed."); + if (!file.delete()) { + Log.err("Fail to delete file. => " + file); + return null; + } else { + Log.log("Success to delete file. => " + file); + } + } + + File parentDir = file.getParentFile(); + if (!parentDir.exists()) { + if (!parentDir.mkdirs()) { + return null; + } + } + + return parentDir; + } + + public static int getParentCnt(String filePath) { + StringTokenizer token = new StringTokenizer(filePath, DIRECTORY_SEPERATOR); + int count = token.countTokens(); + + return count - 1; // except file. + } + /** * Make hidden file. * @param file @@ -912,8 +960,8 @@ public class PathUtil { * @param fromFilePath * @param toFilePath */ - public static void moveFile(String fromFilePath, String toFilePath) { - PathUtil.moveFile(new File(fromFilePath), new File(toFilePath)); + public static boolean moveFile(String fromFilePath, String toFilePath) { + return PathUtil.moveFile(new File(fromFilePath), new File(toFilePath)); } /** -- 2.7.4