public boolean accept(File dir, String name) { File currentFile = new File(dir, name); if (currentFile.isDirectory()) { return sfm.isEntryValid(currentFile, true); } //For ".war" and ".rar", check all files in the archive if (name.endsWith(".war") || name.endsWith(".rar")) { return sfm.isEntryValid(currentFile, true); } String path = currentFile.getAbsolutePath(); if (!path.startsWith(libDir) && path.endsWith(".jar")) { return sfm.isEntryValid(currentFile, true); } return false; } }
private boolean deleteEntry(String name, final boolean isLogging) { name = name.replace('/', File.separatorChar); File input = new File(archive, name); if (!input.exists() || ! isEntryValid(input, isLogging)) { return false; } final boolean result = input.delete(); staleFileManager.recordDeletedEntry(input); return result; }
/** * @returns an @see java.io.OutputStream for a new entry in this * current abstract archive. * @param name the entry name */ @Override public OutputStream putNextEntry(String name) throws java.io.IOException { name = name.replace('/', File.separatorChar); File newFile = new File(archive, name); if (newFile.exists()) { if (!deleteEntry(name, false /* isLogging */)) { logger.log(Level.FINE, "Could not delete file {0} in FileArchive {1} during putNextEntry; continuing", new Object[]{name, uri.toASCIIString()}); } } // if the entry name contains directory structure, we need // to create those directories first. if (name.lastIndexOf(File.separatorChar)!=-1) { String dirs = name.substring(0, name.lastIndexOf(File.separatorChar)); (new File(archive, dirs)).mkdirs(); } staleFileManager().recordValidEntry(newFile); os = new BufferedOutputStream(new FileOutputStream(newFile)); return os; }
/** * create or obtain an embedded archive within this abstraction. * * @param name name of the embedded archive. */ @Override public WritableArchive createSubArchive(String name) throws IOException { String subEntryName = getFileSubArchivePath(name); File subEntry = new File(subEntryName); if (!subEntry.exists()) { // time to create a new sub directory subEntry.mkdirs(); logger.log(DEBUG_LEVEL, "FileArchive.createSubArchive created dirs for {0}", subEntry.getAbsolutePath()); } else { logger.log(DEBUG_LEVEL, "FileArchive.createSubArchive found existing dir for {0}", subEntry.getAbsolutePath()); /* * This subdirectory already exists, so it might be marked as * stale. Because this invocation is creating the subarchive in * the current archive, the subdirectory is no longer stale. */ staleFileManager().recordValidEntry(subEntry); } final WritableArchive result = archiveFactory.createArchive(subEntry); if (result instanceof AbstractReadableArchive) { ((AbstractReadableArchive) result).setParentArchive(this); } return result; }
/** * utility method for deleting a directory and all its content */ private boolean deleteDir(File directory) throws IOException { if (!directory.isDirectory()) { throw new FileNotFoundException(directory.getPath()); } boolean allDeletesSucceeded = true; // delete contents File[] entries = directory.listFiles(); for (int i=0;i<entries.length;i++) { if (entries[i].isDirectory()) { allDeletesSucceeded &= deleteDir(entries[i]); } else { if ( ! entries[i].equals(StaleFileManager.Util.markerFile(archive))) { final boolean fileDeleteOK = FileUtils.deleteFile(entries[i]); if (fileDeleteOK) { staleFileManager.recordDeletedEntry(entries[i]); } allDeletesSucceeded &= fileDeleteOK; } } } // delete self return (allDeletesSucceeded && FileUtils.deleteFile(directory)); }
public boolean accept(File dir, String name) { File currentFile = new File(dir, name); if (currentFile.isDirectory()) { return sfm.isEntryValid(currentFile, true); } //For ".war" and ".rar", check all files in the archive if (name.endsWith(".war") || name.endsWith(".rar")) { return sfm.isEntryValid(currentFile, true); } String path = currentFile.getAbsolutePath(); if (!path.startsWith(libDir) && path.endsWith(".jar")) { return sfm.isEntryValid(currentFile, true); } return false; } }
private boolean isEntryValid(final File entry, final boolean isLogging, final Logger logger) { return staleFileManager().isEntryValid(entry, isLogging, logger); }