[INST] Installmanager can support SDK small patch. 72/19772/1
authoryongsung1.kim <yongsung1.kim@samsung.com>
Fri, 28 Mar 2014 10:11:45 +0000 (19:11 +0900)
committeryongsung1.kim <yongsung1.kim@samsung.com>
Thu, 17 Apr 2014 10:51:39 +0000 (19:51 +0900)
Conflicts:

InstallManager_java/src/org/tizen/installmanager/core/Installer.java
InstallManager_java/src/org/tizen/installmanager/core/Options.java
InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java
InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java

Change-Id: Ibdcb7e0845839fc43c14706101bd60294a2bd08b
Signed-off-by: yongsung1.kim <yongsung1.kim@samsung.com>
InstallManager_java/src/org/tizen/installmanager/cli/CliUnzipImage.java
InstallManager_java/src/org/tizen/installmanager/cli/InstallManagerNoUI.java
InstallManager_java/src/org/tizen/installmanager/core/InstallManagerConstants.java
InstallManager_java/src/org/tizen/installmanager/core/Installer.java
InstallManager_java/src/org/tizen/installmanager/core/Options.java
InstallManager_java/src/org/tizen/installmanager/lib/Patch.java [new file with mode: 0644]
InstallManager_java/src/org/tizen/installmanager/pkg/lib/PackageManager.java
InstallManager_java/src/org/tizen/installmanager/pkg/lib/PropertyParser.java
InstallManager_java/src/org/tizen/installmanager/ui/InstallManagerWindow.java
InstallManager_java/src/org/tizen/installmanager/util/PathUtil.java

index 5f27027..8a106f9 100644 (file)
@@ -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();
index bec35c7..a207469 100644 (file)
@@ -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;
@@ -235,4 +237,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.");
+               }
+       }
 }
index ef49aeb..b1e9d8e 100644 (file)
@@ -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);
+               }
+       }
 }
index 45650f7..fc2b3a9 100644 (file)
@@ -274,7 +274,7 @@ public class Installer {
         * \r
         * @return Environment variables map\r
         */\r
-       private Map<String, String> setEnvironmentVariable() {\r
+       public Map<String, String> setEnvironmentVariable() {\r
                HashMap<String, String> env = new HashMap<String, String>();\r
 \r
                env.put("INSTALLED_PATH", Registry.getInstalledPath());\r
@@ -352,12 +352,12 @@ public class Installer {
                for (int i = 0; i < fromList.length; i++) {\r
                        boolean ret = false;\r
                        if (Platform.isLinux()) {\r
-                               ret = PathUtil.copyHardLink(fromList[i], toFile);\r
+                               ret = PathUtil.copyHardLink(fromList[i], toFile, false);\r
                        } else if (Platform.isWindows()) {\r
                                ret = PathUtil.move(fromList[i],\r
                                                new File(toFile, fromList[i].getName()));\r
                        } else if (Platform.isMacOS()) {\r
-                               ret = PathUtil.copyHardLink(fromList[i], toFile);\r
+                               ret = PathUtil.copyHardLink(fromList[i], toFile, false);\r
                        } else {\r
                                throw new IMFatalException(ErrorCode.UNSUPPORTED_PLATFORM);\r
                        }\r
index 82c2482..cab191d 100644 (file)
@@ -37,6 +37,7 @@ import org.tizen.installmanager.core.Config.ServerType;
 import org.tizen.installmanager.lib.Log;\r
 import org.tizen.installmanager.lib.Platform;\r
 import org.tizen.installmanager.lib.ErrorController.ErrorCode;\r
+import org.tizen.installmanager.lib.Registry;\r
 \r
 /**\r
  * This class represents options from command line arguments.\r
@@ -182,7 +183,13 @@ public class Options {
        \r
        public static String[] args;\r
        \r
-       public static String executablePath = null;\r
+       public static String executablePath = null;
+       
+       /**
+        * SDK patch
+        */
+       public static boolean doSDKPatch = false;
+       public static String SDKPatchPath = null;\r
        \r
        /**\r
         * Parses command line arguments and sets corresponding options. \r
@@ -234,6 +241,24 @@ public class Options {
                                                        " such as specific meta packages or 'all'");\r
                                        throw new IMFatalException(ErrorCode.WRONG_OPTION);\r
                                }\r
+                               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;\r
                        } else if (arg.equalsIgnoreCase("-repoinfo")) {\r
                                if (iter.hasNext()) {\r
@@ -395,7 +420,8 @@ public class Options {
                ArrayList<String> argArray = new ArrayList<String>();\r
 \r
                for (String t : args) {\r
-                       if (!t.equalsIgnoreCase("-install") && !t.equalsIgnoreCase("-remove")) {\r
+                       if (!t.equalsIgnoreCase("-install") && !t.equalsIgnoreCase("-remove")
+                                       && !t.equalsIgnoreCase("-patch")) {\r
                                argArray.add(t);                                \r
                        }\r
                }\r
@@ -430,13 +456,18 @@ public class Options {
                // set SDK image path\r
                argIter = argArray.iterator();\r
                while (argIter.hasNext()) {\r
-                       if (argIter.next().equalsIgnoreCase("-f")) {\r
-                               argIter.remove();\r
-                               imageFilePath = argIter.next();\r
-                               isNetwork = false;\r
-                               serverType = ServerType.LOCAL;\r
-                               argIter.remove();\r
-                               exclusiveOptions("-d", argArray);\r
+                       if (argIter.next().equalsIgnoreCase("-f")) {
+                               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();
+                               }\r
                        }\r
                }\r
                \r
@@ -581,5 +612,13 @@ public class Options {
                                throw new IMFatalException("[" + option + "] cannot be used with some options.");\r
                        }\r
                }\r
+       }
+       
+       private static boolean canSDKPatch() {
+               if (Registry.isInstalled()) {
+                       return true;
+               } else {
+                       return false;
+               }
        }\r
 }\r
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 (file)
index 0000000..6247c42
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+ *  InstallManager
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * Donghee Yang <donghee.yang@samsung.com>
+ * Shihyun Kim <shihyun.kim@samsung.com>
+ * Yongsung kim <yongsung1.kim@samsung.com>
+ * 
+ * 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<PropertySection> 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<String> 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 <code>true</code> if success
+        * @throws IMShellCommandFail
+        */
+       public boolean executeScript(File scriptFile) throws IMShellCommandFail {
+               scriptFile.setExecutable(true);
+               Installer installer = new Installer();
+               Map<String, String> 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<PropertySection> sectionsInstalled = null;
+               List<PropertySection> 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;
+       }
+}
index 12305ba..712eead 100644 (file)
@@ -421,7 +421,7 @@ public abstract class PackageManager {
         * @param destPackages It is set of packages.\r
         * @param repoToSectionsMap It is added to <code>destPackages</code>\r
         */\r
-       private boolean setPackages(PackageSet destPackages, Map<String,List<PropertySection>> repoToSectionsMap, boolean isExtensionPackage) {\r
+       public boolean setPackages(PackageSet destPackages, Map<String,List<PropertySection>> repoToSectionsMap, boolean isExtensionPackage) {\r
                if (destPackages == null) {\r
                        destPackages = new PackageSet();\r
                }\r
@@ -1770,7 +1770,18 @@ public abstract class PackageManager {
        }\r
        \r
        return pSections;\r
-    }\r
+    }
+       
+       public PropertySection savePropertySectionsFromPackages(Package pkg) {
+               PropertySection pSection = null;
+               Properties properties = null;
+               
+               properties = (Properties)pkg.getProperties();
+               pSection = new PropertySection();
+               pSection.setProperties(properties);
+               
+               return pSection;
+       }\r
        \r
        /**\r
         * Check the repository change.\r
index c86f6e8..35add02 100644 (file)
@@ -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);     
index a391868..b58be1a 100644 (file)
@@ -66,6 +66,7 @@ import org.tizen.installmanager.core.Config;
 import org.tizen.installmanager.core.IMExitException;\r
 import org.tizen.installmanager.core.IMFatalException;\r
 import org.tizen.installmanager.core.InstallManager;\r
+import org.tizen.installmanager.core.InstallManagerConstants;\r
 import org.tizen.installmanager.core.Options;\r
 import org.tizen.installmanager.core.Performance;\r
 import org.tizen.installmanager.lib.ErrorController;\r
@@ -893,7 +894,10 @@ public class InstallManagerWindow extends ApplicationWindow {
                        } else if (Options.doShowPackageListNoUI) {\r
                                InstallManagerNoUI.cliShowPackageList();\r
                        } else if (Options.doShowSDKInstallStatus) {\r
-                               InstallManagerNoUI.cliShowInstallInformation();\r
+                               InstallManagerNoUI.cliShowInstallInformation();
+                       } else if (Options.doSDKPatch) {
+                               InstallManagerNoUI.cliSDKPatch();
+                               System.exit(0);\r
                        } else {\r
                                window.open();\r
                                if (Display.getCurrent() != null\r
@@ -910,7 +914,14 @@ public class InstallManagerWindow extends ApplicationWindow {
                        Log.log("Gracefully exit");\r
                } catch (Throwable e) {\r
                        Log.err("Unexpected error occurred");\r
-                       Log.ExceptionLog(e);\r
+                       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);
+                       }\r
                        \r
                        if (Options.doInstallNoUI || Options.doRemoveNoUI) {\r
                                PathUtil.remove(Registry.REGISTRY_FILE_PATH);\r
index a4f9938..bc6888b 100644 (file)
@@ -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;
@@ -164,11 +165,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) {
@@ -180,17 +185,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
@@ -578,6 +597,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
@@ -908,8 +956,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));
        }
        
        /**