Skip to content

Commit eb6f8a7

Browse files
committed
Add RPM 4.12.0/6.0.0 large file support
1 parent 26ca653 commit eb6f8a7

File tree

17 files changed

+2595
-96
lines changed

17 files changed

+2595
-96
lines changed

rpm/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java

Lines changed: 948 additions & 0 deletions
Large diffs are not rendered by default.

rpm/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java

Lines changed: 637 additions & 0 deletions
Large diffs are not rendered by default.

rpm/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java

Lines changed: 515 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.commons.compress.archivers.cpio;
20+
21+
/**
22+
* All constants needed by CPIO.
23+
* <p>
24+
* Based on code from the <a href="jrpm.sourceforge.net">jRPM project</a>.
25+
* </p>
26+
* <p>
27+
* A list of the {@code C_xxx} constants is <a href="http://www.opengroup.org/onlinepubs/9699919799/basedefs/cpio.h.html">here</a>.
28+
* </p>
29+
* <p>
30+
* TODO Next major version: Update to a class.
31+
* </p>
32+
*/
33+
public interface CpioConstants {
34+
/** Magic number of a cpio entry in the new format */
35+
String MAGIC_NEW = "070701";
36+
37+
/** Magic number of a cpio entry in the new format with CRC */
38+
String MAGIC_NEW_CRC = "070702";
39+
40+
/** Magic number of a cpio entry in the old ASCII format */
41+
String MAGIC_OLD_ASCII = "070707";
42+
43+
/** Magic number of a cpio entry in the old binary format */
44+
int MAGIC_OLD_BINARY = 070707;
45+
46+
/** Magic number of a cpio entry in the stripped format */
47+
String MAGIC_STRIPPED = "07070X";
48+
49+
/** Write/read a CpioArchiveEntry in the new format. FORMAT_ constants are internal. */
50+
short FORMAT_NEW = 1;
51+
52+
/** Write/read a CpioArchiveEntry in the new format with CRC. FORMAT_ constants are internal. */
53+
short FORMAT_NEW_CRC = 2;
54+
55+
/** Write/read a CpioArchiveEntry in the old ASCII format. FORMAT_ constants are internal. */
56+
short FORMAT_OLD_ASCII = 4;
57+
58+
/** Write/read a CpioArchiveEntry in the old binary format. FORMAT_ constants are internal. */
59+
short FORMAT_OLD_BINARY = 8;
60+
61+
/** Write/read a CpioArchiveEntry in the stripped format. FORMAT_ constants are internal. */
62+
short FORMAT_STRIPPED = 16;
63+
64+
/** Mask for both new formats. FORMAT_ constants are internal. */
65+
short FORMAT_NEW_MASK = 3;
66+
67+
/** Mask for both old formats. FORMAT_ constants are internal. */
68+
short FORMAT_OLD_MASK = 12;
69+
70+
/*
71+
* Constants for the MODE bits
72+
*/
73+
74+
/** Mask for all file type bits. */
75+
int S_IFMT = 0170000;
76+
77+
/** Defines a socket */
78+
int C_ISSOCK = 0140000;
79+
80+
/** Defines a symbolic link */
81+
int C_ISLNK = 0120000;
82+
83+
/** HP/UX network special (C_ISCTG) */
84+
int C_ISNWK = 0110000;
85+
86+
/** Defines a regular file */
87+
int C_ISREG = 0100000;
88+
89+
/** Defines a block device */
90+
int C_ISBLK = 0060000;
91+
92+
/** Defines a directory */
93+
int C_ISDIR = 0040000;
94+
95+
/** Defines a character device */
96+
int C_ISCHR = 0020000;
97+
98+
/** Defines a pipe */
99+
int C_ISFIFO = 0010000;
100+
101+
/** Sets user ID */
102+
int C_ISUID = 0004000;
103+
104+
/** Sets group ID */
105+
int C_ISGID = 0002000;
106+
107+
/** On directories, restricted deletion flag. */
108+
int C_ISVTX = 0001000;
109+
110+
/** Permits the owner of a file to read the file */
111+
int C_IRUSR = 0000400;
112+
113+
/** Permits the owner of a file to write to the file */
114+
int C_IWUSR = 0000200;
115+
116+
/** Permits the owner of a file to execute the file or to search the directory */
117+
int C_IXUSR = 0000100;
118+
119+
/** Permits a file's group to read the file */
120+
int C_IRGRP = 0000040;
121+
122+
/** Permits a file's group to write to the file */
123+
int C_IWGRP = 0000020;
124+
125+
/** Permits a file's group to execute the file or to search the directory */
126+
int C_IXGRP = 0000010;
127+
128+
/** Permits others to read the file */
129+
int C_IROTH = 0000004;
130+
131+
/** Permits others to write to the file */
132+
int C_IWOTH = 0000002;
133+
134+
/** Permits others to execute the file or to search the directory */
135+
int C_IXOTH = 0000001;
136+
137+
/** The special trailer marker */
138+
String CPIO_TRAILER = "TRAILER!!!";
139+
140+
/**
141+
* The default block size.
142+
*
143+
* @since 1.1
144+
*/
145+
int BLOCK_SIZE = 512;
146+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2015, 2019 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
14+
package org.eclipse.packager.rpm;
15+
16+
public enum RpmFormat {
17+
RPM_3(3),
18+
RPM_4(4),
19+
RPM_6(6);
20+
21+
public static final RpmFormat DEFAULT = RPM_4;
22+
23+
private final int format;
24+
25+
RpmFormat(final int format) {
26+
this.format = format;
27+
}
28+
29+
public int getFormat() {
30+
return this.format;
31+
}
32+
33+
public static RpmFormat fromFormat(final int format) {
34+
switch (format) {
35+
case 3:
36+
return RPM_3;
37+
case 4:
38+
return RPM_4;
39+
case 6:
40+
return RPM_6;
41+
default:
42+
throw new IllegalArgumentException("Unknown RPM format: " + format);
43+
}
44+
}
45+
46+
@Override
47+
public String toString() {
48+
return String.valueOf(this.format);
49+
}
50+
}

rpm/src/main/java/org/eclipse/packager/rpm/RpmTag.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import java.util.Map;
1818

1919
public enum RpmTag implements RpmBaseTag {
20+
HEADER_SIGNATURES(62, byte[].class),
21+
HEADER_IMMUTABLE(63, byte[].class),
22+
HEADER_I18NTABLE(100, String.class),
2023
NAME(1000, String.class),
2124
VERSION(1001, String.class),
2225
RELEASE(1002, String.class),
@@ -94,6 +97,10 @@ public enum RpmTag implements RpmBaseTag {
9497
POSTTRANSACTION_SCRIPT(1152, String.class),
9598
PRETRANSACTION_SCRIPT_PROG(1153, String[].class),
9699
POSTTRANSACTION_SCRIPT_PROG(1154, String[].class),
100+
/**
101+
* File size (when files > 4GB are present). Always used in RPM 6.
102+
*/
103+
LONG_FILE_SIZES(5008, Long[].class),
97104
LONGSIZE(5009, Long.class),
98105
FILE_DIGESTALGO(5011, Integer.class),
99106
RECOMMEND_NAME(5046, String[].class),
@@ -108,16 +115,34 @@ public enum RpmTag implements RpmBaseTag {
108115
ENHANCE_NAME(5055, String[].class),
109116
ENHANCE_VERSION(5056, String[].class),
110117
ENHANCE_FLAGS(5057, Integer[].class),
118+
/**
119+
* Encoding of the header string data. When present it is always "utf-8" and the data has actually been validated.
120+
* Always present in RPM 6.
121+
*/
122+
ENCODING(5062, String.class),
111123

112124
PAYLOAD_DIGEST(5092, String[].class),
113125
PAYLOAD_DIGEST_ALGO(5093, Integer.class),
114-
PAYLOAD_DIGEST_ALT(5097, String[].class);
126+
PAYLOAD_DIGEST_ALT(5097, String[].class),
127+
128+
/**
129+
* The compressed payload size.
130+
*/
131+
PAYLOAD_SIZE(5112, Long.class),
132+
/**
133+
* The uncompressed payload size.
134+
*/
135+
PAYLOAD_SIZE_ALT(5113, Long.class),
136+
/**
137+
* The RPM version number (version 6 or later).
138+
*/
139+
RPM_FORMAT(5114, Integer.class);
115140

116141
private final Integer value;
117142

118143
private final Class<?> dataType;
119144

120-
<T> RpmTag(final Integer value, Class<T> dataType) {
145+
<T> RpmTag(final Integer value, final Class<T> dataType) {
121146
this.value = value;
122147
this.dataType = dataType;
123148
}
@@ -145,7 +170,7 @@ public static RpmTag find(final Integer value) {
145170

146171
@Override
147172
public String toString() {
148-
RpmTag tag = find(this.value);
173+
final RpmTag tag = find(this.value);
149174
return dataType.getSimpleName() + " " + (tag != null ? tag.name() + "(" + this.value + ")" : "UNKNOWN(" + this.value + ")");
150175
}
151176
}

rpm/src/main/java/org/eclipse/packager/rpm/Rpms.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public class Rpms {
3131

3232
public static final byte[] EMPTY_128;
3333

34-
public static final int IMMUTABLE_TAG_SIGNATURE = 62;
34+
public static final int IMMUTABLE_TAG_SIGNATURE = RpmTag.HEADER_SIGNATURES.getValue();
3535

36-
public static final int IMMUTABLE_TAG_HEADER = 63;
36+
public static final int IMMUTABLE_TAG_HEADER = RpmTag.HEADER_IMMUTABLE.getValue();
3737

3838
static {
3939
EMPTY_128 = new byte[128];

rpm/src/main/java/org/eclipse/packager/rpm/build/BuilderOptions.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.LinkedList;
2424
import java.util.List;
2525

26+
import org.eclipse.packager.rpm.RpmFormat;
2627
import org.eclipse.packager.rpm.coding.PayloadCoding;
2728
import org.eclipse.packager.rpm.coding.PayloadFlags;
2829

@@ -38,6 +39,7 @@ public class BuilderOptions {
3839

3940
private static final PayloadFlags DEFAULT_PAYLOAD_FLAGS = new PayloadFlags(DEFAULT_PAYLOAD_CODING, 9);
4041

42+
private int rpmFormat = RpmFormat.DEFAULT.getFormat();
4143

4244
private LongMode longMode = LongMode.DEFAULT;
4345

@@ -59,11 +61,12 @@ public BuilderOptions() {
5961
try {
6062
this.payloadProcessors.add(PayloadProcessors.payloadDigest(DigestAlgorithm.SHA256));
6163
} catch (final Exception e) {
62-
// We silently ignore the case that SHA1 isn't available
64+
// We silently ignore the case that SHA256 isn't available
6365
}
6466
}
6567

6668
public BuilderOptions(final BuilderOptions other) {
69+
setRpmFormat(other.rpmFormat);
6770
setLongMode(other.longMode);
6871
setOpenOptions(other.openOptions);
6972
setFileNameProvider(other.fileNameProvider);
@@ -74,6 +77,18 @@ public BuilderOptions(final BuilderOptions other) {
7477
setPayloadProcessors(other.payloadProcessors);
7578
}
7679

80+
public int getRpmFormat() {
81+
return this.rpmFormat;
82+
}
83+
84+
public void setRpmFormat(final int rpmFormat) {
85+
this.rpmFormat = RpmFormat.fromFormat(rpmFormat).getFormat();
86+
87+
if (this.rpmFormat >= 6) {
88+
this.payloadProcessors.add(PayloadProcessors.payloadSize());
89+
}
90+
}
91+
7792
public LongMode getLongMode() {
7893
return this.longMode;
7994
}

rpm/src/main/java/org/eclipse/packager/rpm/build/PayloadProcessors.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,51 @@ private PayloadProcessors() {
2727
}
2828

2929
/**
30-
* Create the payload digest values for @{link {@link RpmTag#PAYLOAD_DIGEST}
31-
* and @{link
32-
* {@link RpmTag#PAYLOAD_DIGEST_ALT}}
30+
* Create the payload size values for @{link {@link RpmTag#PAYLOAD_SIZE} and {@link RpmTag#PAYLOAD_SIZE_ALT}}.
31+
*/
32+
public static PayloadProcessor payloadSize() {
33+
return new PayloadProcessor() {
34+
private long payloadSize;
35+
36+
private long archiveSize;
37+
38+
@Override
39+
public void feedRawPayloadData(final ByteBuffer data) {
40+
payloadSize += data.remaining();
41+
}
42+
43+
@Override
44+
public void feedCompressedPayloadData(final ByteBuffer data) {
45+
archiveSize += data.remaining();
46+
}
47+
48+
@Override
49+
public void finish(final Header<RpmTag> header) {
50+
header.putLong(RpmTag.PAYLOAD_SIZE, payloadSize);
51+
header.putLong(RpmTag.PAYLOAD_SIZE_ALT, archiveSize);
52+
}
53+
};
54+
}
55+
56+
/**
57+
* Create the payload digest values for @{link {@link RpmTag#PAYLOAD_DIGEST} and {@link RpmTag#PAYLOAD_DIGEST_ALT}}.
3358
*
34-
* @param algorithm The digest algorithm to use.
59+
* @param algorithm The digest algorithm to use
3560
* @return The payload processor
36-
* @throws NoSuchAlgorithmException In case the algorithm isn't supported by the
37-
* JVM.
61+
* @throws NoSuchAlgorithmException In case the algorithm isn't supported by the JVM
3862
*/
3963
public static PayloadProcessor payloadDigest(final DigestAlgorithm algorithm) throws NoSuchAlgorithmException {
4064
final MessageDigest digestRaw = algorithm.createDigest();
4165
final MessageDigest digestCompressed = algorithm.createDigest();
4266

4367
return new PayloadProcessor() {
44-
4568
@Override
46-
public void feedRawPayloadData(ByteBuffer data) {
69+
public void feedRawPayloadData(final ByteBuffer data) {
4770
digestRaw.update(data);
4871
}
4972

5073
@Override
51-
public void feedCompressedPayloadData(ByteBuffer data) {
74+
public void feedCompressedPayloadData(final ByteBuffer data) {
5275
digestCompressed.update(data);
5376
}
5477

@@ -62,5 +85,4 @@ public void finish(final Header<RpmTag> header) {
6285
}
6386
};
6487
}
65-
6688
}

0 commit comments

Comments
 (0)