From 7ec591ddc0861edc2fbee5ef0eabac4e023de1a6 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Thu, 28 Jun 2007 13:39:36 +0000
Subject: [PATCH] This commit address issue 1674 <https://opends.dev.java.net/issues/show_bug.cgi?id=1674> to make the webstart and offline installers cancelable. The plumbing for cancelability is already in place since the upgrader makes use of it. This commit for the most part implements the actions that the installers must perform when the operation is canceled.
---
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java | 78 +++++++++++++++++++++++++++++++++++++--
1 files changed, 74 insertions(+), 4 deletions(-)
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
index f578716..8b3c1f9 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
@@ -112,6 +112,44 @@
}
/**
+ * Renames the source file to the target file. If the target file exists
+ * it is first deleted. The rename and delete operation return values
+ * are checked for success and if unsuccessful, this method throws an
+ * exception.
+ *
+ * @param fileToRename The file to rename.
+ * @param target The file to which <code>fileToRename</code> will be
+ * moved.
+ * @throws ApplicationException If a problem occurs while attempting to rename
+ * the file. On the Windows platform, this typically
+ * indicates that the file is in use by this or another
+ * application.
+ */
+ public void rename(File fileToRename, File target)
+ throws ApplicationException {
+ if (fileToRename != null && target != null) {
+ synchronized (target) {
+ if (target.exists()) {
+ if (!target.delete()) {
+ throw new ApplicationException(
+ ApplicationException.Type.FILE_SYSTEM_ERROR,
+ getMsg("error-deleting-file",
+ Utils.getPath(target)), null);
+ }
+ }
+ }
+ if (!fileToRename.renameTo(target)) {
+ throw new ApplicationException(
+ ApplicationException.Type.FILE_SYSTEM_ERROR,
+ getMsg("error-renaming-file",
+ Utils.getPath(fileToRename),
+ Utils.getPath(target)), null);
+ }
+ }
+ }
+
+
+ /**
* Move a file.
* @param object File to move
* @param newParent File representing new parent directory
@@ -167,6 +205,23 @@
}
/**
+ * Deletes the children of a directory.
+ *
+ * @param parentDir the directory whose children is deleted
+ * @throws ApplicationException if there is a problem deleting children
+ */
+ public void deleteChildren(File parentDir) throws ApplicationException {
+ if (parentDir != null && parentDir.exists() && parentDir.isDirectory()) {
+ File[] children = parentDir.listFiles();
+ if (children != null) {
+ for (File child : children) {
+ delete(child);
+ }
+ }
+ }
+ }
+
+ /**
* Deletes everything below the specified file.
*
* @param file the path to be deleted.
@@ -198,12 +253,15 @@
*
* @param objectFile the file to be copied.
* @param destDir the directory to copy the file to
+ * @return File representing the destination
* @throws ApplicationException if something goes wrong.
*/
- public void copy(File objectFile, File destDir)
+ public File copy(File objectFile, File destDir)
throws ApplicationException
{
- new CopyOperation(objectFile, destDir, false).apply();
+ CopyOperation co = new CopyOperation(objectFile, destDir, false);
+ co.apply();
+ return co.getDestination();
}
/**
@@ -211,13 +269,16 @@
*
* @param objectFile the file to be copied.
* @param destDir the directory to copy the file to
+ * @return File representing the destination
* @param overwrite overwrite destination files.
* @throws ApplicationException if something goes wrong.
*/
- public void copy(File objectFile, File destDir, boolean overwrite)
+ public File copy(File objectFile, File destDir, boolean overwrite)
throws ApplicationException
{
- new CopyOperation(objectFile, destDir, overwrite).apply();
+ CopyOperation co = new CopyOperation(objectFile, destDir, overwrite);
+ co.apply();
+ return co.getDestination();
}
/**
@@ -372,6 +433,15 @@
}
/**
+ * Returns the destination file that is the result of copying
+ * <code>objectFile</code> to <code>destDir</code>.
+ * @return
+ */
+ public File getDestination() {
+ return this.destination;
+ }
+
+ /**
* {@inheritDoc}
*/
public void apply() throws ApplicationException {
--
Gitblit v1.10.0