Example #1
0
  private static void addControlEntry(
      final String pName, final String pContent, final TarArchiveOutputStream pOutput)
      throws IOException {
    final byte[] data = pContent.getBytes("UTF-8");

    final TarArchiveEntry entry = new TarArchiveEntry("./" + pName, true);
    entry.setSize(data.length);
    entry.setNames("root", "root");

    if (MAINTAINER_SCRIPTS.contains(pName)) {
      entry.setMode(PermMapper.toMode("755"));
    } else {
      entry.setMode(PermMapper.toMode("644"));
    }

    pOutput.putArchiveEntry(entry);
    pOutput.write(data);
    pOutput.closeArchiveEntry();
  }
Example #2
0
  /**
   * Build control archive of the deb
   *
   * @param pControlFiles
   * @param pDataSize
   * @param pChecksums
   * @param pOutput
   * @return
   * @throws FileNotFoundException
   * @throws IOException
   * @throws ParseException
   */
  private PackageDescriptor buildControl(
      final File[] pControlFiles,
      final BigInteger pDataSize,
      final StringBuffer pChecksums,
      final File pOutput)
      throws IOException, ParseException {

    PackageDescriptor packageDescriptor = null;

    final TarOutputStream outputStream =
        new TarOutputStream(new GZIPOutputStream(new FileOutputStream(pOutput)));
    outputStream.setLongFileMode(TarOutputStream.LONGFILE_GNU);

    for (int i = 0; i < pControlFiles.length; i++) {
      final File file = pControlFiles[i];

      if (file.isDirectory()) {
        continue;
      }

      final TarEntry entry = new TarEntry(file);

      final String name = file.getName();

      entry.setName("./" + name);
      entry.setNames("root", "root");
      entry.setMode(PermMapper.toMode("755"));

      if ("control".equals(name)) {
        packageDescriptor = new PackageDescriptor(new FileInputStream(file), resolver);

        if (packageDescriptor.get("Date") == null) {
          SimpleDateFormat fmt =
              new SimpleDateFormat(
                  "EEE, d MMM yyyy HH:mm:ss Z",
                  Locale.ENGLISH); // Mon, 26 Mar 2007 11:44:04 +0200 (RFC 2822)
          // FIXME Is this field allowed in package descriptors ?
          packageDescriptor.set("Date", fmt.format(new Date()));
        }

        if (packageDescriptor.get("Distribution") == null) {
          packageDescriptor.set("Distribution", "unknown");
        }

        if (packageDescriptor.get("Urgency") == null) {
          packageDescriptor.set("Urgency", "low");
        }

        final String debFullName = System.getenv("DEBFULLNAME");
        final String debEmail = System.getenv("DEBEMAIL");

        if (debFullName != null && debEmail != null) {
          packageDescriptor.set("Maintainer", debFullName + " <" + debEmail + ">");
          console.println("Using maintainer from the environment variables.");
        }

        continue;
      }

      final InputStream inputStream = new FileInputStream(file);

      outputStream.putNextEntry(entry);

      Utils.copy(inputStream, outputStream);

      outputStream.closeEntry();

      inputStream.close();
    }

    if (packageDescriptor == null) {
      throw new FileNotFoundException("No control file in " + Arrays.toString(pControlFiles));
    }

    packageDescriptor.set("Installed-Size", pDataSize.divide(BigInteger.valueOf(1024)).toString());

    addEntry("control", packageDescriptor.toString(), outputStream);

    addEntry("md5sums", pChecksums.toString(), outputStream);

    outputStream.close();

    return packageDescriptor;
  }