[izpack-changes] r1569 - izpack-src/trunk/src/lib/com/izforge/izpack/uninstaller
noreply at berlios.de
noreply at berlios.de
Wed Sep 6 22:33:48 CEST 2006
Author: eppelman
Date: 2006-09-06 22:33:47 +0200 (Wed, 06 Sep 2006)
New Revision: 1569
Modified:
izpack-src/trunk/src/lib/com/izforge/izpack/uninstaller/Destroyer.java
Log:
-implemented the X-KDE subsitute user - shortcut attribute (see Unix_shortcutSpec.xml).
-write Desktop shortcuts to all known local and ypbinded users "desktop" folders.
-write common shortcuts to the new freedesktop.org common "/usr/share/applications"
and "/usr/share/pixmaps" folders to display these in the commons [start].menu
Here: updated the uninstaller
Modified: izpack-src/trunk/src/lib/com/izforge/izpack/uninstaller/Destroyer.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/uninstaller/Destroyer.java 2006-09-06 20:33:14 UTC (rev 1568)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/uninstaller/Destroyer.java 2006-09-06 20:33:47 UTC (rev 1569)
@@ -26,14 +26,21 @@
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
import com.izforge.izpack.ExecutableFile;
import com.izforge.izpack.event.UninstallerListener;
+import com.izforge.izpack.installer.UninstallData;
import com.izforge.izpack.util.AbstractUIProgressHandler;
+import com.izforge.izpack.util.Debug;
import com.izforge.izpack.util.FileExecutor;
+import com.izforge.izpack.util.os.unix.ShellScript;
+import com.izforge.izpack.util.os.unix.UnixHelper;
+import com.izforge.izpack.util.os.unix.UnixUser;
/**
* The files destroyer class.
@@ -107,6 +114,8 @@
// Custem action listener stuff --- afterDeletion ----
informListeners(listeners[0], UninstallerListener.AFTER_DELETION, files, handler);
+ removeRootFiles(getRootFiles());
+
// We make a complementary cleanup
handler.progress(size, "[ cleanups ]");
cleanup(new File(installPath));
@@ -126,22 +135,21 @@
*
* @exception Exception Description of the Exception
*/
-// private void askUninstallerRemoval() throws Exception
-// {
-// // Initialisations
-// InputStream in = Destroyer.class.getResourceAsStream("/jarlocation.log");
-// InputStreamReader inReader = new InputStreamReader(in);
-// BufferedReader reader = new BufferedReader(inReader);
-//
-// // We delete
-// File jar = new File(reader.readLine());
-// File path = new File(reader.readLine());
-// File inst = new File(installPath);
-// jar.deleteOnExit();
-// path.deleteOnExit();
-// inst.deleteOnExit();
-// }
-
+ // private void askUninstallerRemoval() throws Exception
+ // {
+ // // Initialisations
+ // InputStream in = Destroyer.class.getResourceAsStream("/jarlocation.log");
+ // InputStreamReader inReader = new InputStreamReader(in);
+ // BufferedReader reader = new BufferedReader(inReader);
+ //
+ // // We delete
+ // File jar = new File(reader.readLine());
+ // File path = new File(reader.readLine());
+ // File inst = new File(installPath);
+ // jar.deleteOnExit();
+ // path.deleteOnExit();
+ // inst.deleteOnExit();
+ // }
/**
* Returns an ArrayList of the files to delete.
*
@@ -186,6 +194,77 @@
}
/**
+ * Gets the root files.
+ *
+ * @return The files which should remove by root for another user
+ * @throws Exception
+ */
+ private Hashtable getRootFiles() throws Exception
+ {
+ Hashtable result = new Hashtable();
+ ObjectInputStream in = new ObjectInputStream(Destroyer.class.getResourceAsStream("/"
+ + UninstallData.RootFiles));
+ int num = in.readInt();
+ for (int i = 0; i < num; i++)
+ {
+ String file = (String) in.readObject();
+
+ UnixUser user = (UnixUser) in.readObject();
+ result.put(file, user);
+ }
+ return result;
+ }
+
+ /**
+ * Removes the given files as root for the given Users
+ *
+ * @param entries The files to reomove for the users
+ */
+ private void removeRootFiles(Hashtable entries)
+ {
+ Enumeration e = entries.keys();
+
+ String su = UnixHelper.getSuCommand();
+ String rm = UnixHelper.getCustomCommand("rm");
+ String S = " ";
+
+ while (e.hasMoreElements())
+ {
+ String filename = (String) e.nextElement();
+ UnixUser user = (UnixUser) entries.get(filename);
+
+ StringBuffer script = new StringBuffer();
+
+ script.append(su);
+ script.append(S);
+ script.append(user.getName());
+ script.append(S);
+ script.append("-c");
+ script.append(S);
+ script.append('"');
+ script.append(rm);
+ script.append(S);
+ script.append(filename);
+ script.append('"');
+
+ Debug.log("Executes: " + script.toString());
+
+ try
+ {
+ String result = ShellScript.execAndDelete(script, File.createTempFile(
+ this.getClass().getName(),
+ Long.toString(System.currentTimeMillis()) + ".sh").toString());
+ Debug.log("Result: " + result);
+ }
+ catch (Exception ex)
+ {
+ Debug.log("Exeption during su remove: " + ex.getMessage());
+ }
+
+ }
+ }
+
+ /**
* Makes some reccursive cleanups.
*
* @param file The file to wipe.
More information about the izpack-changes
mailing list