/** Test case for PLXCOMP-220. */
  public void testInvalidUidGid() {
    final TarArchiveEntry writtenEntry = new TarArchiveEntry("test.java");
    writtenEntry.setUserId(-1);
    writtenEntry.setGroupId(-1);
    final byte[] buffer = new byte[defaultRcdsize()];
    writtenEntry.writeEntryHeader(buffer);

    final TarArchiveEntry readEntry = new TarArchiveEntry(buffer);
    assertEquals(0, readEntry.getUserId());
    assertEquals(0, readEntry.getGroupId());
  }
Exemple #2
0
  public TarArchiveEntry map(final TarArchiveEntry entry) {
    final String name = entry.getName();

    final TarArchiveEntry newEntry =
        new TarArchiveEntry(prefix + '/' + Utils.stripPath(strip, name), true);

    // Set ownership
    if (uid > -1) {
      newEntry.setUserId(uid);
    } else {
      newEntry.setUserId(entry.getUserId());
    }
    if (gid > -1) {
      newEntry.setGroupId(gid);
    } else {
      newEntry.setGroupId(entry.getGroupId());
    }
    if (user != null) {
      newEntry.setUserName(user);
    } else {
      newEntry.setUserName(entry.getUserName());
    }
    if (group != null) {
      newEntry.setGroupName(group);
    } else {
      newEntry.setGroupName(entry.getGroupName());
    }

    // Set permissions
    if (newEntry.isDirectory()) {
      if (dirMode > -1) {
        newEntry.setMode(dirMode);
      } else {
        newEntry.setMode(entry.getMode());
      }
    } else {
      if (fileMode > -1) {
        newEntry.setMode(fileMode);
      } else {
        newEntry.setMode(entry.getMode());
      }
    }

    newEntry.setSize(entry.getSize());

    return newEntry;
  }