void put(final URI uri, ArtifactData data) throws Exception { reporter.trace("put %s %s", uri, data); File tmp = createTempFile(repoDir, "mtp", ".whatever"); tmp.deleteOnExit(); try { copy(uri.toURL(), tmp); byte[] sha = SHA1.digest(tmp).digest(); reporter.trace("SHA %s %s", uri, Hex.toHexString(sha)); ArtifactData existing = get(sha); if (existing != null) { reporter.trace("existing"); xcopy(existing, data); return; } File meta = new File(repoDir, Hex.toHexString(sha) + ".json"); File file = new File(repoDir, Hex.toHexString(sha)); rename(tmp, file); reporter.trace("file %s", file); data.file = file.getAbsolutePath(); data.sha = sha; data.busy = false; CommandData cmddata = parseCommandData(data); if (cmddata.bsn != null) { data.name = cmddata.bsn + "-" + cmddata.version; } else data.name = Strings.display(cmddata.title, cmddata.bsn, cmddata.name, uri); codec.enc().to(meta).put(data); reporter.trace("TD = " + data); } finally { tmp.delete(); reporter.trace("puted %s %s", uri, data); } }
/** * Deletes the directory passed as parameters * * @param dir the directory to delete */ public static void deleteDir(File dir) { File[] list = dir.listFiles(); for (int i = 0; i < list.length; i++) { if (list[i].isDirectory()) deleteDir(list[i]); else list[i].delete(); } dir.delete(); }
/** * Takes an input File containing the pack file, and generates a JarOutputStream. * * <p>Does not close its output. (The output can accumulate more elements.) * * @param in a File. * @param out a JarOutputStream. * @exception IOException if an error is encountered. */ public void unpack(File in, JarOutputStream out) throws IOException { // Use the stream-based implementation. // %%% Reconsider if native unpacker learns to memory-map the file. FileInputStream instr = new FileInputStream(in); unpack(instr, out); if (_props.getBoolean(Utils.UNPACK_REMOVE_PACKFILE)) { in.delete(); } }
public static void cleanUpUnpacked(File libDir) { if (libDir.exists() && libDir.listFiles(new ExtFilter(".gz")).length > 0) { for (File gz : libDir.listFiles(new ExtFilter(".gz"))) { try { gz.delete(); } catch (Exception e) { } } } }
public static void removePreviousLibs(File libDir) { if (libDir.exists() && libDir.listFiles(new PrefixFilter("runwar")).length > 0) { for (File previous : libDir.listFiles(new PrefixFilter("runwar"))) { try { previous.delete(); } catch (Exception e) { System.err.println("Could not delete previous lib: " + previous.getAbsolutePath()); } } } }
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; }
/** * Garbage collect repository * * @throws Exception */ public void gc() throws Exception { HashSet<byte[]> deps = new HashSet<byte[]>(); // deps.add(SERVICE_JAR_FILE); for (File cmd : commandDir.listFiles()) { CommandData data = getData(CommandData.class, cmd); addDependencies(deps, data); } for (File service : serviceDir.listFiles()) { File dataFile = new File(service, "data"); ServiceData data = getData(ServiceData.class, dataFile); addDependencies(deps, data); } int count = 0; for (File f : repoDir.listFiles()) { String name = f.getName(); if (!deps.contains(name)) { if (!name.endsWith(".json") || !deps.contains(name.substring(0, name.length() - ".json".length()))) { // Remove // json // files // only // if // the // bin // is // going // as // well f.delete(); count++; } else { } } } System.out.format("Garbage collection done (%d file(s) removed)%n", count); }
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(); } }
/** * Creates the java help * * @param path the path where to create the java help * @param lang the spoken language */ private void createJavaHelp(File path, String lang) { File pages = new File(path, "pages"); if (pages.exists()) deleteDir(pages); pages.mkdir(); File javahelpsearch = new File(path, SEARCH_DIR); if (javahelpsearch.exists()) deleteDir(javahelpsearch); File helpset_file = new File(path, HELPSET_NAME_BASE + lang + HELPSET_NAME_SUFFIX); File config_file = null; File map_file = null; File tam_file = null; String underscore = ""; if (helpset_file.exists()) { // There is a helpset corresponding to the current language map_file = new File(path, MAP_NAME_BASE + lang + MAP_NAME_SUFFIX); tam_file = new File(path, TAM_NAME_BASE + lang + TAM_NAME_SUFFIX); underscore = "_" + lang; } else { // There is no helpset : we use the default one map_file = new File(path + "Map.jhm"); tam_file = new File(path + "TAM.xml"); } config_file = new File(path, CONFIG_FILE); if (config_file.exists()) config_file.delete(); if (map_file.exists()) map_file.delete(); if (tam_file.exists()) tam_file.delete(); boolean test = true; try { // Generates the jhm and copy the file for objects // Generates the TAM.xml file test = test && map_file.createNewFile(); test = test && tam_file.createNewFile(); File lang_dir = new File(path, "Main_pages/" + lang); test = test && lang_dir.exists(); if (test) { print = new PrintWriter(new BufferedWriter(new FileWriter(map_file))); // debut + images print.println( "<?xml version='1.0' encoding='ISO-8859-1' ?>\n " + "<!DOCTYPE map\n" + "PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\"\n" + "\"http://java.sun.com/products/javahelp/map_1_0.dtd\">\n" + "\n" + "<map version=\"1.0\">\n" + "<mapID target=\"image\" url=\"Main_pages/logo_cbs_petit.gif\" />\n" + "<mapID target=\"tamicon\" url=\"Main_pages/tam.gif\" />\n" + "<mapID target=\"fileicon\" url=\"Main_pages/file.gif\" />\n" + "<mapID target=\"" + FIRST_PAGE + "\" url=\"pages/" + FIRST_PAGE + ".html\" />"); print2 = new PrintWriter(new BufferedWriter(new FileWriter(tam_file))); print2.println( " <?xml version='1.0' encoding='ISO-8859-1' ?> \n " + "<!DOCTYPE toc \n" + "PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 2.0//EN\"\n" + "\"../dtd/toc_2_0.dtd\">\n" + "<toc version=\"2.0\"> \n<tocitem text=\"" + getTitle(new File(path, "Main_pages/" + lang + "/" + FIRST_PAGE + ".html")) + "\" target=\"" + FIRST_PAGE + "\" image=\"image\">"); copyFile( new File(path, "Main_pages/" + lang + "/" + FIRST_PAGE + ".html"), new File(path, "pages/" + FIRST_PAGE + ".html")); // generation of the tree File[] list_lang_dir = lang_dir.listFiles(); for (int a = 0; a < list_lang_dir.length; a++) { if (!list_lang_dir[a].getName().equals("CVS") && list_lang_dir[a].isFile() && !list_lang_dir[a].getName().equals(FIRST_PAGE + ".html")) { mapAndTocForFile(list_lang_dir[a], path, underscore); } } // Ends print.println("</map>"); print.close(); print2.println("</tocitem>\n</toc>"); print2.close(); test = test && config_file.createNewFile(); if (test) { // Generates the config file print = new PrintWriter(new BufferedWriter(new FileWriter(config_file))); print.print("IndexRemove " + path.getAbsolutePath()); print.close(); } } } catch (Exception e) { LOG.error("Error getHelp " + e); } // Generates the search database String[] args = new String[] { pages.getAbsolutePath(), "-c", config_file.getAbsolutePath(), "-db", javahelpsearch.getAbsolutePath(), "-locale", lang }; // Indexer indexer=new Indexer(); // FIXME help desactived // Indexer.main(args); Calendar c = GregorianCalendar.getInstance(); c.setTime(new Date()); int day = c.get(Calendar.DAY_OF_MONTH); int month = c.get(Calendar.MONTH) + 1; int year = c.get(Calendar.YEAR); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); int seconds = c.get(Calendar.SECOND); File log = new File(path, LOG_FILE); try { log.createNewFile(); PrintWriter printlog = new PrintWriter(new BufferedWriter(new FileWriter(log))); printlog.println("Language " + lang); printlog.println( "Date : " + year + " " + month + " " + day + " " + hour + " " + minute + " " + seconds); printlog.close(); } catch (Exception e) { LOG.error("Error while creating log " + e); } }
/** The run method. */ public void run() { instances.add(this); try { listener.startUnpack(); String currentOs = System.getProperty("os.name").toLowerCase(); // // Initialisations FileOutputStream out = null; ArrayList parsables = new ArrayList(); ArrayList executables = new ArrayList(); List packs = idata.selectedPacks; int npacks = packs.size(); udata = UninstallData.getInstance(); // Specific to the web installers if (idata.kind.equalsIgnoreCase("web") || idata.kind.equalsIgnoreCase("web-kunststoff")) { InputStream kin = getClass().getResourceAsStream("/res/WebInstallers.url"); BufferedReader kreader = new BufferedReader(new InputStreamReader(kin)); jarLocation = kreader.readLine(); } // We unpack the selected packs for (int i = 0; i < npacks; i++) { // We get the pack stream int n = idata.allPacks.indexOf(packs.get(i)); ObjectInputStream objIn = new ObjectInputStream(getPackAsStream(n)); // We unpack the files int nfiles = objIn.readInt(); listener.changeUnpack(0, nfiles, ((Pack) packs.get(i)).name); for (int j = 0; j < nfiles; j++) { // We read the header PackFile pf = (PackFile) objIn.readObject(); if (null == pf.os || matchOS(currentOs, pf.os.toLowerCase())) { // We translate & build the path String path = translatePath(pf.targetPath); File pathFile = new File(path); String fname = pathFile.getName(); int z = fname.length(); File dest = pathFile.getParentFile(); if (!dest.exists()) dest.mkdirs(); // We add the path to the log, udata.addFile(path); listener.progressUnpack(j, path); // if this file exists and shouldnot override skip this file if (((pf.override == false) && (pathFile.exists()))) { objIn.skip(pf.length); continue; } // We copy the file out = new FileOutputStream(path); byte[] buffer = new byte[5120]; long bytesCopied = 0; while (bytesCopied < pf.length) { int maxBytes = (pf.length - bytesCopied < buffer.length ? (int) (pf.length - bytesCopied) : buffer.length); int bytesInBuffer = objIn.read(buffer, 0, maxBytes); if (bytesInBuffer == -1) throw new IOException("Unexpected end of stream"); out.write(buffer, 0, bytesInBuffer); bytesCopied += bytesInBuffer; } // Cleanings out.close(); // Empty dirs restoring String _n = pathFile.getName(); if (_n.startsWith("izpack-keepme") && _n.endsWith(".tmp")) pathFile.delete(); } else objIn.skip(pf.length); } // Load information about parsable files int numParsables = objIn.readInt(); int k; for (k = 0; k < numParsables; k++) { ParsableFile pf = (ParsableFile) objIn.readObject(); pf.path = translatePath(pf.path); parsables.add(pf); } // Load information about executable files int numExecutables = objIn.readInt(); for (k = 0; k < numExecutables; k++) { ExecutableFile ef = (ExecutableFile) objIn.readObject(); ef.path = translatePath(ef.path); if (null != ef.argList && !ef.argList.isEmpty()) { String arg = null; for (int j = 0; j < ef.argList.size(); j++) { arg = (String) ef.argList.get(j); arg = translatePath(arg); ef.argList.set(j, arg); } } executables.add(ef); if (ef.executionStage == ExecutableFile.UNINSTALL) { udata.addExecutable(ef); } } objIn.close(); } // We use the scripts parser ScriptParser parser = new ScriptParser(parsables, vs); parser.parseFiles(); // We use the file executor FileExecutor executor = new FileExecutor(executables); if (executor.executeFiles(ExecutableFile.POSTINSTALL) != 0) javax.swing.JOptionPane.showMessageDialog( null, "The installation was not completed.", "Installation warning", javax.swing.JOptionPane.WARNING_MESSAGE); // We put the uninstaller putUninstaller(); // The end :-) listener.stopUnpack(); } catch (Exception err) { listener.stopUnpack(); listener.errorUnpack(err.toString()); } instances.remove(instances.indexOf(this)); }
/** Starts main program with the specified arguments. */ public synchronized boolean run(String args[]) { ok = true; if (!parseArgs(args)) { return false; } try { if (cflag || uflag) { if (fname != null) { // The name of the zip file as it would appear as its own // zip file entry. We use this to make sure that we don't // add the zip file to itself. zname = fname.replace(File.separatorChar, '/'); if (zname.startsWith("./")) { zname = zname.substring(2); } } } if (cflag) { Manifest manifest = null; InputStream in = null; if (!Mflag) { if (mname != null) { in = new FileInputStream(mname); manifest = new Manifest(new BufferedInputStream(in)); } else { manifest = new Manifest(); } addVersion(manifest); addCreatedBy(manifest); if (isAmbiguousMainClass(manifest)) { if (in != null) { in.close(); } return false; } if (ename != null) { addMainClass(manifest, ename); } if (pname != null) { if (!addProfileName(manifest, pname)) { if (in != null) { in.close(); } return false; } } } OutputStream out; if (fname != null) { out = new FileOutputStream(fname); } else { out = new FileOutputStream(FileDescriptor.out); if (vflag) { // Disable verbose output so that it does not appear // on stdout along with file data // error("Warning: -v option ignored"); vflag = false; } } expand(null, files, false); create(new BufferedOutputStream(out, 4096), manifest); if (in != null) { in.close(); } out.close(); } else if (uflag) { File inputFile = null, tmpFile = null; FileInputStream in; FileOutputStream out; if (fname != null) { inputFile = new File(fname); tmpFile = createTempFileInSameDirectoryAs(inputFile); in = new FileInputStream(inputFile); out = new FileOutputStream(tmpFile); } else { in = new FileInputStream(FileDescriptor.in); out = new FileOutputStream(FileDescriptor.out); vflag = false; } InputStream manifest = (!Mflag && (mname != null)) ? (new FileInputStream(mname)) : null; expand(null, files, true); boolean updateOk = update(in, new BufferedOutputStream(out), manifest, null); if (ok) { ok = updateOk; } in.close(); out.close(); if (manifest != null) { manifest.close(); } if (ok && fname != null) { // on Win32, we need this delete inputFile.delete(); if (!tmpFile.renameTo(inputFile)) { tmpFile.delete(); throw new IOException(getMsg("error.write.file")); } tmpFile.delete(); } } else if (tflag) { replaceFSC(files); if (fname != null) { list(fname, files); } else { InputStream in = new FileInputStream(FileDescriptor.in); try { list(new BufferedInputStream(in), files); } finally { in.close(); } } } else if (xflag) { replaceFSC(files); if (fname != null && files != null) { extract(fname, files); } else { InputStream in = (fname == null) ? new FileInputStream(FileDescriptor.in) : new FileInputStream(fname); try { extract(new BufferedInputStream(in), files); } finally { in.close(); } } } else if (iflag) { genIndex(rootjar, files); } } catch (IOException e) { fatalError(e); ok = false; } catch (Error ee) { ee.printStackTrace(); ok = false; } catch (Throwable t) { t.printStackTrace(); ok = false; } out.flush(); err.flush(); return ok; }