Port of fixes for https://issues.apache.org/jira/browse/COMPRESS-314 and https://issues.apache.org/jira/browse/COMPRESS-315master
| @@ -121,6 +121,11 @@ Other changes: | |||
| <ftp> and <get>. | |||
| github pull requests #8 and #9 | |||
| * The <tar> package can now deal with group and user ids bigger than | |||
| 0x80000000. | |||
| https://issues.apache.org/jira/browse/COMPRESS-314 | |||
| https://issues.apache.org/jira/browse/COMPRESS-315 | |||
| Changes from Ant 1.9.3 TO Ant 1.9.4 | |||
| =================================== | |||
| @@ -119,10 +119,10 @@ public class TarEntry implements TarConstants { | |||
| private int mode; | |||
| /** The entry's user id. */ | |||
| private int userId; | |||
| private long userId; | |||
| /** The entry's group id. */ | |||
| private int groupId; | |||
| private long groupId; | |||
| /** The entry's size. */ | |||
| private long size; | |||
| @@ -422,9 +422,12 @@ public class TarEntry implements TarConstants { | |||
| * Get this entry's user id. | |||
| * | |||
| * @return This entry's user id. | |||
| * @deprecated use #getLongUserId instead as user ids can be | |||
| * bigger than {@link Integer.MAX_INT} | |||
| */ | |||
| @Deprecated | |||
| public int getUserId() { | |||
| return userId; | |||
| return (int) (userId & 0xffffffff); | |||
| } | |||
| /** | |||
| @@ -433,6 +436,26 @@ public class TarEntry implements TarConstants { | |||
| * @param userId This entry's new user id. | |||
| */ | |||
| public void setUserId(int userId) { | |||
| setUserId((long) userId); | |||
| } | |||
| /** | |||
| * Get this entry's user id. | |||
| * | |||
| * @return This entry's user id. | |||
| * @since 1.9.5 | |||
| */ | |||
| public long getLongUserId() { | |||
| return userId; | |||
| } | |||
| /** | |||
| * Set this entry's user id. | |||
| * | |||
| * @param userId This entry's new user id. | |||
| * @since 1.9.5 | |||
| */ | |||
| public void setUserId(long userId) { | |||
| this.userId = userId; | |||
| } | |||
| @@ -440,9 +463,12 @@ public class TarEntry implements TarConstants { | |||
| * Get this entry's group id. | |||
| * | |||
| * @return This entry's group id. | |||
| * @deprecated use #getLongGroupId instead as group ids can be | |||
| * bigger than {@link Integer.MAX_INT} | |||
| */ | |||
| @Deprecated | |||
| public int getGroupId() { | |||
| return groupId; | |||
| return (int) (groupId & 0xffffffff); | |||
| } | |||
| /** | |||
| @@ -451,6 +477,26 @@ public class TarEntry implements TarConstants { | |||
| * @param groupId This entry's new group id. | |||
| */ | |||
| public void setGroupId(int groupId) { | |||
| setGroupId((long) groupId); | |||
| } | |||
| /** | |||
| * Get this entry's group id. | |||
| * | |||
| * @return This entry's group id. | |||
| * @since 1.9.5 | |||
| */ | |||
| public long getLongGroupId() { | |||
| return groupId; | |||
| } | |||
| /** | |||
| * Set this entry's group id. | |||
| * | |||
| * @param groupId This entry's new group id. | |||
| * @since 1.9.5 | |||
| */ | |||
| public void setGroupId(long groupId) { | |||
| this.groupId = groupId; | |||
| } | |||
| @@ -484,11 +484,11 @@ public class TarInputStream extends FilterInputStream { | |||
| } else if ("linkpath".equals(key)){ | |||
| currEntry.setLinkName(val); | |||
| } else if ("gid".equals(key)){ | |||
| currEntry.setGroupId(Integer.parseInt(val)); | |||
| currEntry.setGroupId(Long.parseLong(val)); | |||
| } else if ("gname".equals(key)){ | |||
| currEntry.setGroupName(val); | |||
| } else if ("uid".equals(key)){ | |||
| currEntry.setUserId(Integer.parseInt(val)); | |||
| currEntry.setUserId(Long.parseLong(val)); | |||
| } else if ("uname".equals(key)){ | |||
| currEntry.setUserName(val); | |||
| } else if ("size".equals(key)){ | |||
| @@ -161,7 +161,7 @@ public class TarOutputStream extends FilterOutputStream { | |||
| /** | |||
| * Set the long file mode. | |||
| * This can be LONGFILE_ERROR(0), LONGFILE_TRUNCATE(1) or LONGFILE_GNU(2). | |||
| * This specifies the treatment of long file names (names >= TarConstants.NAMELEN). | |||
| * This specifies the treatment of long file names (names >= TarConstants.NAMELEN). | |||
| * Default is LONGFILE_ERROR. | |||
| * @param longFileMode the mode to use | |||
| */ | |||
| @@ -512,7 +512,7 @@ public class TarOutputStream extends FilterOutputStream { | |||
| private String stripTo7Bits(String name) { | |||
| final int length = name.length(); | |||
| StringBuffer result = new StringBuffer(length); | |||
| StringBuilder result = new StringBuilder(length); | |||
| for (int i = 0; i < length; i++) { | |||
| char stripped = (char) (name.charAt(i) & 0x7F); | |||
| if (stripped != 0) { // would be read as Trailing null | |||
| @@ -538,12 +538,12 @@ public class TarOutputStream extends FilterOutputStream { | |||
| TarEntry entry) { | |||
| addPaxHeaderForBigNumber(paxHeaders, "size", entry.getSize(), | |||
| TarConstants.MAXSIZE); | |||
| addPaxHeaderForBigNumber(paxHeaders, "gid", entry.getGroupId(), | |||
| addPaxHeaderForBigNumber(paxHeaders, "gid", entry.getLongGroupId(), | |||
| TarConstants.MAXID); | |||
| addPaxHeaderForBigNumber(paxHeaders, "mtime", | |||
| entry.getModTime().getTime() / 1000, | |||
| TarConstants.MAXSIZE); | |||
| addPaxHeaderForBigNumber(paxHeaders, "uid", entry.getUserId(), | |||
| addPaxHeaderForBigNumber(paxHeaders, "uid", entry.getLongUserId(), | |||
| TarConstants.MAXID); | |||
| // star extensions by J\u00f6rg Schilling | |||
| addPaxHeaderForBigNumber(paxHeaders, "SCHILY.devmajor", | |||
| @@ -564,11 +564,11 @@ public class TarOutputStream extends FilterOutputStream { | |||
| private void failForBigNumbers(TarEntry entry) { | |||
| failForBigNumber("entry size", entry.getSize(), TarConstants.MAXSIZE); | |||
| failForBigNumber("group id", entry.getGroupId(), TarConstants.MAXID); | |||
| failForBigNumberWithPosixMessage("group id", entry.getLongGroupId(), TarConstants.MAXID); | |||
| failForBigNumber("last modification time", | |||
| entry.getModTime().getTime() / 1000, | |||
| TarConstants.MAXSIZE); | |||
| failForBigNumber("user id", entry.getUserId(), TarConstants.MAXID); | |||
| failForBigNumber("user id", entry.getLongUserId(), TarConstants.MAXID); | |||
| failForBigNumber("mode", entry.getMode(), TarConstants.MAXID); | |||
| failForBigNumber("major device number", entry.getDevMajor(), | |||
| TarConstants.MAXID); | |||
| @@ -577,6 +577,14 @@ public class TarOutputStream extends FilterOutputStream { | |||
| } | |||
| private void failForBigNumber(String field, long value, long maxValue) { | |||
| failForBigNumber(field, value, maxValue, ""); | |||
| } | |||
| private void failForBigNumberWithPosixMessage(String field, long value, long maxValue) { | |||
| failForBigNumber(field, value, maxValue, " Use STAR or POSIX extensions to overcome this limit"); | |||
| } | |||
| private void failForBigNumber(String field, long value, long maxValue, String additionalMsg) { | |||
| if (value < 0 || value > maxValue) { | |||
| throw new RuntimeException(field + " '" + value | |||
| + "' is too big ( > " | |||