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;
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);
}
/**
* 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);
ZipInputStream zis = null;
ZipEntry zipEntry = null;
int work = 1;
+ int cnt = 0;
try {
fis = new FileInputStream(imageFile);
}
} 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.");
}
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);
}
}
@SuppressWarnings("unused")
- private boolean validation(String strDir) {
+ private boolean validation(String strDir, UNZIP_FILE_STYLE style) {
ZipFile zipFile = null;
ZipEntry entry = null;
}
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();
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;
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;
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;
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.");
+ }
+ }
}
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);
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);
+ }
+ }
}
*
* @return Environment variables map
*/
- private Map<String, String> setEnvironmentVariable() {
+ public Map<String, String> setEnvironmentVariable() {
HashMap<String, String> env = new HashMap<String, String>();
env.put("INSTALLED_PATH", Registry.getInstalledPath());
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);
}
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.
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
*/
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;
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);
}
}
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();
+ }
}
}
}
}
}
+
+ private static boolean canSDKPatch() {
+ if (Registry.isInstalled()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
--- /dev/null
+/*
+ * 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;
+ }
+}
* @param destPackages It is set of packages.
* @param repoToSectionsMap It is added to <code>destPackages</code>
*/
- private boolean setPackages(PackageSet destPackages, Map<String,List<PropertySection>> repoToSectionsMap, boolean isExtensionPackage) {
+ public boolean setPackages(PackageSet destPackages, Map<String,List<PropertySection>> repoToSectionsMap, boolean isExtensionPackage) {
if (destPackages == null) {
destPackages = new PackageSet();
}
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
}
//end of file.
- if (sReadData == null) {
+ if (sReadData == null || sReadData.startsWith("#")) {
if (pFieldList.size() > 0) {
pSection = new PropertySection();
pSection.setProperties(pFieldList);
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;
InstallManagerNoUI.cliShowPackageList();
} else if (Options.doShowSDKInstallStatus) {
InstallManagerNoUI.cliShowInstallInformation();
+ } else if (Options.doSDKPatch) {
+ InstallManagerNoUI.cliSDKPatch();
+ System.exit(0);
} else {
window.open();
if (Display.getCurrent() != null
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);
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;
* @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) {
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
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
* @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));
}
/**