예제 #1
0
 /** Gets the basenames header values. */
 public String[] getBaseNames() {
   String[] array = new String[headers.size()];
   int x = 0;
   for (CpioHeader header : headers)
     array[x++] = normalizePath(new File(header.getName()).getName());
   return array;
 }
예제 #2
0
 /** Gets the devices header values. */
 public int[] getDevices() {
   int[] array = new int[headers.size()];
   int x = 0;
   for (CpioHeader header : headers)
     array[x++] = (header.getDevMajor() << 8) + header.getDevMinor();
   return array;
 }
예제 #3
0
 /** Gets the rdevs header values. */
 public short[] getRdevs() {
   short[] array = new short[headers.size()];
   int x = 0;
   for (CpioHeader header : headers)
     array[x++] = (short) ((header.getRdevMajor() << 8) + header.getRdevMinor());
   return array;
 }
예제 #4
0
 /** Gets the mtimes header values. */
 public int[] getMtimes() {
   int[] array = new int[headers.size()];
   int x = 0;
   for (CpioHeader header : headers) {
     array[x++] = header.getMtime();
   }
   return array;
 }
예제 #5
0
 /** Gets the groups header values. */
 public String[] getGroups() {
   String[] array = new String[headers.size()];
   int x = 0;
   for (CpioHeader header : headers) {
     array[x++] = header.getGname() == null ? "root" : header.getGname();
   }
   return array;
 }
예제 #6
0
  /** Gets the dirnames headers values. */
  public String[] getDirNames() {
    final Set<String> set = new LinkedHashSet<String>();
    for (CpioHeader header : headers) {
      String path = new File(header.getName()).getParent();
      if (path == null) continue;

      String parent = normalizePath(path);
      if (!parent.endsWith("/")) parent += "/";
      set.add(parent);
    }
    return set.toArray(new String[set.size()]);
  }
예제 #7
0
 /**
  * Adds a directory entry to the archive with the specified permissions.
  *
  * @param path the destination path for the installed file.
  * @param permissions the permissions flags.
  */
 public synchronized void addLink(String path, final String target, int permissions) {
   if (files.contains(path)) return;
   files.add(path);
   logger.log(FINE, "Adding link ''{0}''.", path);
   CpioHeader header = new CpioHeader(path);
   header.setType(SYMLINK);
   header.setFileSize(target.length());
   header.setMtime(System.currentTimeMillis());
   if (permissions != -1) header.setPermissions(permissions);
   headers.add(header);
   sources.put(header, target);
 }
예제 #8
0
  // TODO: Fix this (as part of general refactoring) to be much better.
  public int[] getDirIndexes() {
    final List<String> dirs = asList(getDirNames());
    int[] array = new int[headers.size()];
    int x = 0;
    for (CpioHeader header : headers) {
      String path = new File(header.getName()).getParent();
      if (path == null) continue;

      String parent = normalizePath(path);
      if (!parent.endsWith("/")) parent += "/";
      array[x++] = dirs.indexOf(parent);
    }
    return array;
  }
예제 #9
0
 /** Gets the sizes header values. */
 public int[] getSizes() {
   int[] array = new int[headers.size()];
   int x = 0;
   try {
     for (CpioHeader header : headers) {
       Object object = sources.get(header);
       if (object instanceof File) array[x] = (int) ((File) object).length();
       else if (object instanceof URL)
         array[x] = ((URL) object).openConnection().getContentLength();
       else if (header.getType() == DIR) array[x] = 4096;
       ++x;
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   return array;
 }
예제 #10
0
  /**
   * Adds a URL entry to the archive with the specified permissions.
   *
   * @param path the destination path for the installed file.
   * @param source the URL with the data to be added
   * @param permissions the permissions flags.
   * @param directive directive indicating special handling for this file.
   * @param uname user owner for the given file
   * @param gname group owner for the given file
   */
  public synchronized void addURL(
      final String path,
      final URL source,
      final int permissions,
      final Directive directive,
      final String uname,
      final String gname,
      final int dirmode)
      throws FileNotFoundException {
    if (files.contains(path)) return;

    addParents(new File(path), dirmode, uname, gname);
    files.add(path);
    logger.log(FINE, "Adding file ''{0}''.", path);
    CpioHeader header = new CpioHeader(path, source);
    header.setType(FILE);
    header.setInode(inode++);
    if (uname != null) header.setUname(uname);
    if (gname != null) header.setGname(gname);
    if (permissions != -1) header.setPermissions(permissions);
    headers.add(header);
    sources.put(header, source);

    if (directive != null) header.setFlags(directive.flag());
  }
예제 #11
0
 /**
  * Scans a file and prints out useful information. This utility reads from standard input, and
  * parses the binary contents of the RPM file.
  *
  * @throws Exception if an error occurs while reading the RPM file or it's contents
  */
 public static void main(String[] args) throws Exception {
   InputStream fios = new FileInputStream(args[0]);
   ReadableChannelWrapper in = new ReadableChannelWrapper(Channels.newChannel(fios));
   Format format = new Scanner().run(in);
   System.out.println(format);
   InputStream uncompressed = new GZIPInputStream(fios);
   in = new ReadableChannelWrapper(Channels.newChannel(uncompressed));
   CpioHeader header;
   int total = 0;
   do {
     header = new CpioHeader();
     total = header.read(in, total);
     System.out.println(header);
     final int skip = header.getFileSize();
     if (uncompressed.skip(skip) != skip) throw new RuntimeException("Skip failed.");
     total += header.getFileSize();
   } while (!header.isLast());
 }
예제 #12
0
  public static File convertRpmToZip(File file) throws Exception {
    LOG.info("File: " + file.getAbsolutePath());

    FileInputStream fis = new FileInputStream(file);
    ReadableChannelWrapper in = new ReadableChannelWrapper(Channels.newChannel(fis));

    InputStream uncompressed = new GZIPInputStream(fis);
    in = new ReadableChannelWrapper(Channels.newChannel(uncompressed));

    String rpmZipName = file.getName();
    rpmZipName = StringUtils.replace(rpmZipName, ".", "-");
    rpmZipName = rpmZipName + ".zip";
    String rpmZipPath = FilenameUtils.getFullPath(file.getAbsolutePath());

    File rpmZipOutput = new File(rpmZipPath + File.separator + rpmZipName);
    LOG.info("Converting RPM: " + file.getName() + " to ZIP: " + rpmZipOutput.getName());
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(rpmZipOutput));

    String rpmName = file.getName();
    rpmName = StringUtils.replace(rpmName, ".", "-");

    CpioHeader header;
    int total = 0;
    do {
      header = new CpioHeader();
      total = header.read(in, total);

      if (header.getFileSize() > 0) {
        BoundedInputStream bis = new BoundedInputStream(uncompressed, header.getFileSize());

        String relPath = FilenameUtils.separatorsToSystem(header.getName());
        relPath = StringUtils.removeStart(relPath, ".");
        relPath = StringUtils.removeStart(relPath, "/");
        relPath = rpmName + File.separator + relPath;
        relPath = StringUtils.replace(relPath, "\\", "/");

        ZipEntry zipEntry = new ZipEntry(relPath);
        zos.putNextEntry(zipEntry);
        IOUtils.copy(bis, zos);
      } else {
        final int skip = header.getFileSize();
        if (uncompressed.skip(skip) != skip) throw new RuntimeException("Skip failed.");
      }

      total += header.getFileSize();
    } while (!header.isLast());

    zos.flush();
    zos.close();

    return rpmZipOutput;
  }
예제 #13
0
  /**
   * Adds a directory entry to the archive with the specified permissions.
   *
   * @param path the destination path for the installed file.
   * @param permissions the permissions flags.
   * @param directive directive indicating special handling for this directory.
   * @param uname user owner for the given file
   * @param gname group owner for the given file
   * @param addParents whether to add parent directories to the rpm
   */
  public synchronized void addDirectory(
      final String path,
      final int permissions,
      final Directive directive,
      final String uname,
      final String gname,
      boolean addParents) {
    if (files.contains(path)) return;

    if (addParents) addParents(new File(path), permissions, uname, gname);
    files.add(path);
    logger.log(FINE, "Adding directory ''{0}''.", path);
    CpioHeader header = new CpioHeader(path);
    header.setType(DIR);
    header.setInode(inode++);
    if (uname != null) header.setUname(uname);
    if (gname != null) header.setGname(gname);
    header.setMtime(System.currentTimeMillis());
    if (permissions != -1) header.setPermissions(permissions);
    else header.setPermissions(DEFAULT_DIRECTORY_PERMISSION);
    headers.add(header);
    sources.put(header, "");
    if (directive != null) header.setFlags(directive.flag());
  }
예제 #14
0
 public boolean equals(final CpioHeader one, final CpioHeader two) {
   return one.getName().equals(two.getName());
 }
예제 #15
0
 public int compare(final CpioHeader one, final CpioHeader two) {
   return one.getName().compareTo(two.getName());
 }
예제 #16
0
 /** Gets the inodes header values. */
 public int[] getInodes() {
   int[] array = new int[headers.size()];
   int x = 0;
   for (CpioHeader header : headers) array[x++] = header.getInode();
   return array;
 }
예제 #17
0
 /** Gets the modes header values. */
 public short[] getModes() {
   short[] array = new short[headers.size()];
   int x = 0;
   for (CpioHeader header : headers) array[x++] = (short) header.getMode();
   return array;
 }