/** * Constructs an <tt>XPackFile</tt> from an {@link PackFile}. * * @param file the pack file * @throws IOException if an I/O error occurred */ public XPackFile(PackFile file) throws IOException { super(new File(file.sourcePath), file.getRelativeSourcePath(), file.getTargetPath(), file.osConstraints(), file.override(), file.overrideRenameTo(), file.blockable(), file.getAdditionals(), null); this.position = 0; this.setCondition(file.getCondition()); }
/** * Add a file or directory to be installed. * * @param file the file or basedir to be installed. * @param targetfile path file will be installed to. * @param osList the target operation system(s) of this pack. * @param override what to do if the file already exists when installing * @param condition the condition to decide whether the file should be extracted * @throws FileNotFoundException if the file specified does not exist. */ public void addFile(File baseDir, File file, String targetfile, List<OsModel> osList, OverrideType override, String overrideRenameTo, Blockable blockable, Map additionals, String condition, Map<String, String> pack200Properties) throws IOException { if (!file.exists()) { throw new FileNotFoundException(file.toString()); } PackFile packFile = new PackFile(baseDir, file, targetfile, osList, override, overrideRenameTo, blockable, additionals, pack200Properties); packFile.setLoosePackInfo(pack.isLoose()); packFile.setCondition(condition); files.put(packFile, file); }
/** * Skips a pack file. * * @param packFile the pack file * @param pack the pack * @param packInputStream the pack stream * @throws IOException if the file cannot be skipped */ protected void skip(PackFile packFile, Pack pack, InputStream packInputStream) throws IOException { if (!pack.isLoose() && !packFile.isBackReference() && !packFile.isPack200Jar()) { long size = packFile.size(); logger.fine("|- Condition not fulfilled - skipping pack stream " + packFile.getTargetPath() + " by " + size + " bytes "); skip(packInputStream, packFile.size()); } }
/** * Determines if a file should be unpacked. * * @param file the file to check * @return {@code true} if the file should be unpacked; {@code false} if it should be skipped */ private boolean shouldUnpack(PackFile file) { boolean result = true; if (file.hasCondition()) { result = isConditionTrue(file.getCondition()); } if (result && file.osConstraints() != null && !file.osConstraints().isEmpty()) { result = matcher.matchesCurrentPlatform(file.osConstraints()); } return result; }
boolean pack200 = packFile.isPack200Jar(); logger.fine("File " + packFile.getTargetPath() + " is a backreference, linked to " + linkedPackFile.getTargetPath()); packFile.setLinkedPackFile(linkedPackFile); addFile = false; if (addFile && !packFile.isDirectory()) packFile.setStreamResourceName("packs/pack200-" + packFile.getId()); packFile.setStreamOffset(0); pack200Files.add(packFile); } else packFile.setStreamResourceName(streamResourceName); packFile.setStreamOffset(packOutputStream.getByteCount()); // get the position if (bytesWritten != packFile.length()) packFile.setSize(proxyOutputStream.getByteCount()); if (bytesPacked != packFile.size()) { throw new IOException("File size mismatch when writing " + file); logger.fine("File " + packFile.getTargetPath() + " added compressed as " + comprFormat.toName() + " (" + packFile.length() + " -> " + packFile.size() + " bytes)"); if (bytesWritten != packFile.length())
File resolvedFile = file.getFile(); if (!resolvedFile.exists()) resolvedFile = new File(userDir, file.getRelativeSourcePath()); file = new PackFile(resolvedFile.getParentFile(), resolvedFile, file.getTargetPath(), file.osConstraints(), file.override(), file.overrideRenameTo(), file.blockable(), file.getAdditionals()); logger.warning("Could not find loosely bundled file: " + file.getRelativeSourcePath()); if (prompt.confirm(Prompt.Type.WARNING, "File not found", "Could not find loosely bundled file: " + file.getRelativeSourcePath(), Prompt.Options.OK_CANCEL) == Prompt.Option.OK)
throws IOException String targetPath = packFile.getTargetPath(); File target = new File(path); File dir = target; if (!packFile.isDirectory()) if (packFile.isDirectory()) if (target.exists() && (packFile.override() != OverrideType.OVERRIDE_TRUE) && !isOverwriteFile(packFile, target)) if (!packFile.isBackReference() && !pack.isLoose() && !packFile.isPack200Jar()) long size = packFile.size(); logger.fine("|- No overwrite - skipping pack stream by " + size + " bytes"); skip(packInputStream, size);
if (!pack.isLoose() && packFile.isBackReference()) PackFile linkedPackFile = packFile.getLinkedPackFile(); packStream = resources.getInputStream(ResourceManager.RESOURCE_BASEPATH_DEFAULT + linkedPackFile.getStreamResourceName()); if (!packFile.isPack200Jar()) long size = linkedPackFile.getStreamOffset(); logger.fine("|- Backreference to pack stream (offset: " + size + " bytes"); skip(packStream, size); } else if (packFile.isPack200Jar()) packStream = resources.getInputStream(ResourceManager.RESOURCE_BASEPATH_DEFAULT + packFile.getStreamResourceName()); } else
final boolean isDirectory = packFile.isDirectory(); logger.fine("Unpacking " + (isDirectory?"directory":"file") + " " + packFile.getTargetPath() + " (backreference: " + packFile.isBackReference() + ")"); if (shouldUnpack(packFile))
final long bytesUnpacked = IOUtils.copyLarge(packInputStream, fo, 0, file.size()); fo.flush(); fo.close(); if (bytesUnpacked != file.size()) throw new IOException("File size mismatch when reading from pack: " + file.getRelativeSourcePath()); if (bytesUncompressed != file.length()) throw new IOException("File size mismatch when uncompressing from pack: " + file.getRelativeSourcePath()); throw new IOException("An exception occurred whilst unpacking: " + file.getRelativeSourcePath() + ": " + e.getMessage(), e);
if (!this.isDirectory())
String targetPath = s.getTargetPath(); if (matcher.match(targetDir + "/" + include, targetPath, casesensitive)) String targetPath = s.getTargetPath(); if (matcher.match(exclude, targetPath, casesensitive))
private Pack200.Packer createPack200Packer(PackFile packFile) { Pack200.Packer packer = Pack200.newPacker(); Map<String, String> defaultPackerProperties = packer.properties(); Map<String,String> localPackerProperties = packFile.getPack200Properties(); if (localPackerProperties != null) { defaultPackerProperties.putAll(localPackerProperties); } return packer; }
/** * Determines if a pack file is blockable. * <p/> * Blockable files must be queued using {@link #queue()}. * * @param file the pack file * @return <tt>true</tt> if the file is blockable, otherwise <tt>false</tt> */ private boolean isBlockable(PackFile file) { return queue != null && (file.blockable() != Blockable.BLOCKABLE_NONE); }
private Pack200.Unpacker createPack200Unpacker(PackFile packFile) { Pack200.Unpacker unpacker = Pack200.newUnpacker(); Map<String, String> defaultUnpackerProperties = unpacker.properties(); Map<String, String> localPackerProperties = packFile.getPack200Properties(); if (localPackerProperties != null) { defaultUnpackerProperties.putAll(localPackerProperties); } return unpacker; } }