private void checkSize(ConfigWeb config, Resource dir, long maxSize, ResourceFilter filter) { if (!dir.exists()) return; Resource res = null; int count = ArrayUtil.size(filter == null ? dir.list() : dir.list(filter)); long size = ResourceUtil.getRealSize(dir, filter); PrintWriter out = config.getOutWriter(); SystemOut.printDate(out, "check size of directory [" + dir + "]"); SystemOut.printDate(out, "- current size [" + size + "]"); SystemOut.printDate(out, "- max size [" + maxSize + "]"); int len = -1; while (count > 100000 || size > maxSize) { Resource[] files = filter == null ? dir.listResources() : dir.listResources(filter); if (len == files.length) break; // protect from inifinti loop len = files.length; for (int i = 0; i < files.length; i++) { if (res == null || res.lastModified() > files[i].lastModified()) { res = files[i]; } } if (res != null) { size -= res.length(); try { res.remove(true); count--; } catch (IOException e) { SystemOut.printDate(out, "cannot remove resource " + res.getAbsolutePath()); break; } } res = null; } }
private static Resource createAgentJar(Log log, Config c) throws IOException { Resource trg = getDeployDirectory(c).getRealResource("lucee-external-agent.jar"); if (!trg.exists() || trg.length() == 0) { log.info("Instrumentation", "create " + trg); InputStream jar = InfoImpl.class.getResourceAsStream("/resource/lib/lucee-external-agent.jar"); if (jar == null) { throw new IOException("could not load jar [/resource/lib/lucee-external-agent.jar]"); } IOUtil.copy(jar, trg, true); } return trg; }
private static void addAttachIfNecessary(Config config, Log log) { String srcName = null, trgName = null; String archBits = (SystemUtil.getJREArch() == SystemUtil.ARCH_64) ? "64" : "32"; // Windows if (SystemUtil.isWindows()) { trgName = "attach.dll"; srcName = "windows" + archBits + "/" + trgName; } // Linux else if (SystemUtil.isLinux()) { trgName = "libattach.so"; srcName = "linux" + archBits + "/" + trgName; } // Solaris else if (SystemUtil.isSolaris()) { trgName = "libattach.so"; srcName = "solaris" + archBits + "/" + trgName; } // Mac OSX else if (SystemUtil.isMacOSX()) { trgName = "libattach.dylib"; srcName = "macosx" + archBits + "/" + trgName; } if (srcName != null) { // create dll if necessary Resource binDir = getBinDirectory(config); Resource trg = binDir.getRealResource(trgName); if (!trg.exists() || trg.length() == 0) { log.info("Instrumentation", "deploy /resource/bin/" + srcName + " to " + trg); InputStream src = InfoImpl.class.getResourceAsStream("/resource/bin/" + srcName); try { IOUtil.copy(src, trg, true); } catch (IOException e) { log.log(Log.LEVEL_ERROR, "Instrumentation", e); } } // set directory to library path SystemUtil.addLibraryPathIfNoExist(binDir, log); } }
private static Resource createToolsJar(Config config) throws IOException { Resource dir = getDeployDirectory(config); String os = "bsd"; // used for Mac OS X if (SystemUtil.isWindows()) { os = "windows"; } else if (SystemUtil.isLinux()) { // not MacOSX os = "linux"; } else if (SystemUtil.isSolaris()) { os = "solaris"; } String name = "tools-" + os + "-" + TOOLS_VERSION + ".jar"; Resource trg = dir.getRealResource(name); if (!trg.exists() || trg.length() == 0) { InputStream jar = InfoImpl.class.getResourceAsStream("/resource/lib/" + name); IOUtil.copy(jar, trg, true); } return trg; }
@Override public void init(lucee.runtime.config.Config config, Resource searchDir) throws IOException, SearchException { this.config = config; this.searchDir = searchDir; this.searchFile = searchDir.getRealResource("search.xml"); if (!searchFile.exists() || searchFile.length() == 0) createSearchFile(searchFile); DOMParser parser = new DOMParser(); InputStream is = null; try { is = engine.getIOUtil().toBufferedInputStream(searchFile.getInputStream()); InputSource source = new InputSource(is); parser.parse(source); } catch (SAXException e) { throw new SearchException(e); } finally { engine.getIOUtil().closeSilent(is); } doc = parser.getDocument(); readCollections(config); }