public static void deleteRecursive(File file) { if (!file.exists()) { return; } if (file.isFile()) { file.delete(); } else if (file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { deleteRecursive(files[i]); } file.delete(); } }
private void adjustConfiguration(Element root, File dir) { // If this is an ISN installation and the Edge Server // keystore and truststore files do not exist, then set the configuration // to use the keystore.jks and truststore.jks files instead of the ones // in the default installation. If the Edge Server files do exist, then // delete the keystore.jks and truststore.jks files, just to avoid // confusion. if (programName.equals("ISN")) { Element server = getFirstNamedChild(root, "Server"); Element ssl = getFirstNamedChild(server, "SSL"); String rsnaroot = System.getenv("RSNA_ROOT"); rsnaroot = (rsnaroot == null) ? "/usr/local/edgeserver" : rsnaroot.trim(); String keystore = rsnaroot + "/conf/keystore.jks"; String truststore = rsnaroot + "/conf/truststore.jks"; File keystoreFile = new File(keystore); File truststoreFile = new File(truststore); cp.appendln(Color.black, "Looking for " + keystore); if (keystoreFile.exists() || truststoreFile.exists()) { cp.appendln(Color.black, "...found it [This is an EdgeServer installation]"); // Delete the default files, just to avoid confusion File ks = new File(dir, "keystore.jks"); File ts = new File(dir, "truststore.jks"); boolean ksok = ks.delete(); boolean tsok = ts.delete(); if (ksok && tsok) cp.appendln(Color.black, "...Unused default SSL files were removed"); else { if (!ksok) cp.appendln(Color.black, "...Unable to delete " + ks); if (!tsok) cp.appendln(Color.black, "...Unable to delete " + ts); } } else { cp.appendln(Color.black, "...not found [OK, this is a non-EdgeServer installation]"); ssl.setAttribute("keystore", "keystore.jks"); ssl.setAttribute("keystorePassword", "edge1234"); ssl.setAttribute("truststore", "truststore.jks"); ssl.setAttribute("truststorePassword", "edge1234"); cp.appendln( Color.black, "...SSL attributes were updated for a non-EdgeServer installation"); } } }
public static boolean deleteAll(File file) { boolean b = true; if ((file != null) && file.exists()) { if (file.isDirectory()) { try { File[] files = file.listFiles(); for (File f : files) b &= deleteAll(f); } catch (Exception e) { return false; } } b &= file.delete(); } return b; }
private long persist(File f, ObjectName name) { long deployed = f.lastModified(); try { Element e = (Element) server.getAttribute(name, "Persist"); if (e != null) { XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); Document doc = new Document(); e.detach(); doc.setRootElement(e); File tmp = new File(f.getAbsolutePath() + ".tmp"); FileWriter writer = new FileWriter(tmp); out.output(doc, writer); writer.close(); f.delete(); tmp.renameTo(f); deployed = f.lastModified(); } } catch (Exception ex) { log.warn("persist", ex); } return deployed; }
private void cleanup(File directory) { // Clean up from old installations, removing or renaming files. // Note that directory is the parent of the CTP directory // unless the original installation was done by Bill Weadock's // all-in-one installer for Windows. // Get a file pointing to the CTP directory. // This might be the current directory, or // it might be the CTP child. File dir; if (directory.getName().equals("RSNA")) dir = directory; else dir = new File(directory, "CTP"); // If CTP.jar exists in this directory, it is a really // old CTP main file - not used anymore File ctp = new File(dir, "CTP.jar"); if (ctp.exists()) ctp.delete(); // These are old names for the Launcher.jar file File launcher = new File(dir, "CTP-launcher.jar"); if (launcher.exists()) launcher.delete(); launcher = new File(dir, "TFS-launcher.jar"); if (launcher.exists()) launcher.delete(); // Delete the obsolete CTP-runner.jar file File runner = new File(dir, "CTP-runner.jar"); if (runner.exists()) runner.delete(); // Delete the obsolete MIRC-copier.jar file File copier = new File(dir, "MIRC-copier.jar"); if (copier.exists()) copier.delete(); // Rename the old versions of the properties files File oldprops = new File(dir, "CTP-startup.properties"); File newprops = new File(dir, "CTP-launcher.properties"); File correctprops = new File(dir, "Launcher.properties"); if (oldprops.exists()) { if (newprops.exists() || correctprops.exists()) oldprops.delete(); else oldprops.renameTo(correctprops); } if (newprops.exists()) { if (correctprops.exists()) newprops.delete(); else newprops.renameTo(correctprops); } // Get rid of obsolete startup and shutdown programs File startup = new File(dir, "CTP-startup.jar"); if (startup.exists()) startup.delete(); File shutdown = new File(dir, "CTP-shutdown.jar"); if (shutdown.exists()) shutdown.delete(); // Get rid of the obsolete linux directory File linux = new File(dir, "linux"); if (linux.exists()) { startup = new File(linux, "CTP-startup.jar"); if (startup.exists()) startup.delete(); shutdown = new File(linux, "CTP-shutdown.jar"); if (shutdown.exists()) shutdown.delete(); linux.delete(); } // clean up the libraries directory File libraries = new File(dir, "libraries"); if (libraries.exists()) { // remove obsolete versions of the slf4j libraries // and the dcm4che-imageio libraries File[] files = libraries.listFiles(); for (File file : files) { if (file.isFile()) { String name = file.getName(); if (name.startsWith("slf4j-") || name.startsWith("dcm4che-imageio-rle")) { file.delete(); } } } // remove the email subdirectory File email = new File(libraries, "email"); deleteAll(email); // remove the xml subdirectory File xml = new File(libraries, "xml"); deleteAll(xml); // remove the sftp subdirectory File sftp = new File(libraries, "sftp"); deleteAll(xml); // move edtftpj.jar to the ftp directory File edtftpj = new File(libraries, "edtftpj.jar"); if (edtftpj.exists()) { File ftp = new File(libraries, "ftp"); ftp.mkdirs(); File ftpedtftpj = new File(ftp, "edtftpj.jar"); edtftpj.renameTo(ftpedtftpj); } } // remove the obsolete xml library under dir File xml = new File(dir, "xml"); deleteAll(xml); // remove the dicom profiles so any // obsolete files will disappear File profiles = new File(dir, "profiles"); File dicom = new File(profiles, "dicom"); deleteAll(dicom); dicom.mkdirs(); // Remove the index.html file so it will be rebuilt from // example-index.html when the system next starts. File root = new File(dir, "ROOT"); if (root.exists()) { File index = new File(root, "index.html"); index.delete(); } }
private void deleteFile(File f, String iuuid) { f.delete(); getLog() .info(String.format("Deleted transient descriptor %s (%s)", f.getAbsolutePath(), iuuid)); }