/** * Clears out everything associated with this resource bundle in the hopes that we can download it * afresh and everything will work the next time around. */ public void wipeBundle(boolean deleteJar) { // clear out our cache directory if (_cache != null) { FileUtil.recursiveClean(_cache); } // delete our unpack stamp file if (_unpacked != null) { _unpacked.delete(); } // clear out any .jarv file that Getdown might be maintaining so // that we ensure that it is revalidated File vfile = new File(FileUtil.resuffix(_source, ".jar", ".jarv")); if (vfile.exists() && !vfile.delete()) { log.warning("Failed to delete vfile", "file", vfile); } // close and delete our source jar file if (deleteJar && _source != null) { closeJar(); if (!_source.delete()) { log.warning("Failed to delete source", "source", _source, "exists", _source.exists()); } } }
/** * Called by the resource manager once it has ensured that our resource jar file is up to date and * ready for reading. * * @return true if we successfully unpacked our resources, false if we encountered errors in doing * so. */ public boolean sourceIsReady() { // make a note of our source's last modification time _sourceLastMod = _source.lastModified(); // if we are unpacking files, the time to do so is now if (_unpacked != null && _unpacked.lastModified() != _sourceLastMod) { try { resolveJarFile(); } catch (IOException ioe) { log.warning("Failure resolving jar file", "source", _source, ioe); wipeBundle(true); return false; } log.info("Unpacking into " + _cache + "..."); if (!_cache.exists()) { if (!_cache.mkdir()) { log.warning("Failed to create bundle cache directory", "dir", _cache); closeJar(); // we are hopelessly f****d return false; } } else { FileUtil.recursiveClean(_cache); } // unpack the jar file (this will close the jar when it's done) if (!FileUtil.unpackJar(_jarSource, _cache)) { // if something went awry, delete everything in the hopes // that next time things will work wipeBundle(true); return false; } // if everything unpacked smoothly, create our unpack stamp try { _unpacked.createNewFile(); if (!_unpacked.setLastModified(_sourceLastMod)) { log.warning("Failed to set last mod on stamp file", "file", _unpacked); } } catch (IOException ioe) { log.warning("Failure creating stamp file", "file", _unpacked, ioe); // no need to stick a fork in things at this point } } return true; }