+ directory creation check
diff --git a/plugins/org.eclipse.epp.installer.core/src/org/eclipse/epp/installer/internal/core/Util.java b/plugins/org.eclipse.epp.installer.core/src/org/eclipse/epp/installer/internal/core/Util.java index c0ecdd6..18e4850 100644 --- a/plugins/org.eclipse.epp.installer.core/src/org/eclipse/epp/installer/internal/core/Util.java +++ b/plugins/org.eclipse.epp.installer.core/src/org/eclipse/epp/installer/internal/core/Util.java
@@ -16,7 +16,6 @@ import org.eclipse.epp.installer.core.IErrorConstants; import org.eclipse.epp.installer.core.model.Context; - /** */ public class Util { @@ -25,8 +24,11 @@ /** * Method copyStreams. - * @param is InputStream - * @param os OutputStream + * + * @param is + * InputStream + * @param os + * OutputStream * @throws IOException */ public static void copyStreams(InputStream is, OutputStream os) @@ -41,29 +43,37 @@ /** * Method copyFiles - * @param in File - * @param out File + * + * @param in + * File + * @param out + * File * @throws IOException */ public static void copyFiles(File in, File out) throws IOException { - FileInputStream fis = new FileInputStream(in); + FileInputStream fis = new FileInputStream(in); FileOutputStream fos = new FileOutputStream(out); copyStreams(fis, fos); fis.close(); fos.close(); } - + /** * Method createFileFromStream. - * @param installer Context - * @param file File - * @param content InputStream + * + * @param installer + * Context + * @param file + * File + * @param content + * InputStream * @return IStatus * @throws IOException */ public static IStatus createFileFromStream(Context installer, File file, - InputStream content, long lastModified ) throws IOException { - if (file.exists() && !installer.getOptions().isNoOverwriteWarningDuringInstall() + InputStream content, long lastModified) throws IOException { + if (file.exists() + && !installer.getOptions().isNoOverwriteWarningDuringInstall() && !installer.confirm(IActionConstants.OVERWRITE_FILE, "Overwrite file {0}?", new Object[] { file })) { String message = MessageFormat.format("Cannot create file {0}.", @@ -71,35 +81,43 @@ return new Status(IStatus.INFO, Context.PLUGIN_ID, IErrorConstants.ERROR_USER_SKIPPED, message, null); } - + IPath path = (new Path(file.getAbsolutePath())).removeLastSegments(1); - for (int i=0; i<=path.segmentCount(); i++) { + for (int i = 0; i <= path.segmentCount(); i++) { IPath subPath = path.uptoSegment(i); File dir = new File(subPath.toOSString()); if (!dir.exists()) { - dir.mkdir(); - installer.getInstallLog().addEntry(new InstallLogEntry( - InstallLog.DIRECTORY_CREATED_ENTRY, dir.getAbsolutePath())); + boolean created = dir.mkdir(); + if (created) { + installer.getInstallLog().addEntry( + new InstallLogEntry( + InstallLog.DIRECTORY_CREATED_ENTRY, dir + .getAbsolutePath())); + } else { + return new Status(IStatus.ERROR, Context.PLUGIN_ID, + "Failed to create directory " + + dir.getAbsolutePath()); + } } } - - OutputStream os = new FileOutputStream(file);; + + OutputStream os = new FileOutputStream(file); + ; try { - + copyStreams(content, os); - installer.getInstallLog().addEntry(new InstallLogEntry( - InstallLog.FILE_CREATED_ENTRY, file.getAbsolutePath())); - - } - finally - { + installer.getInstallLog().addEntry( + new InstallLogEntry(InstallLog.FILE_CREATED_ENTRY, file + .getAbsolutePath())); + + } finally { os.close(); } - -// file.setLastModified(lastModified); -// Platform.getPlatform().setFileCreationTime(file.getAbsolutePath(),lastModified); - + + // file.setLastModified(lastModified); + // Platform.getPlatform().setFileCreationTime(file.getAbsolutePath(),lastModified); + return Status.OK_STATUS; } }