Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.commons.compress.archivers.cpio;

/**
* All constants needed by CPIO.
* <p>
* Based on code from the <a href="jrpm.sourceforge.net">jRPM project</a>.
* </p>
* <p>
* A list of the {@code C_xxx} constants is <a href="http://www.opengroup.org/onlinepubs/9699919799/basedefs/cpio.h.html">here</a>.
* </p>
* <p>
* TODO Next major version: Update to a class.
* </p>
*/
public interface CpioConstants {
/** Magic number of a cpio entry in the new format */
String MAGIC_NEW = "070701";

/** Magic number of a cpio entry in the new format with CRC */
String MAGIC_NEW_CRC = "070702";

/** Magic number of a cpio entry in the old ASCII format */
String MAGIC_OLD_ASCII = "070707";

/** Magic number of a cpio entry in the old binary format */
int MAGIC_OLD_BINARY = 070707;

/** Magic number of a cpio entry in the stripped format */
String MAGIC_STRIPPED = "07070X";

/** Write/read a CpioArchiveEntry in the new format. FORMAT_ constants are internal. */
short FORMAT_NEW = 1;

/** Write/read a CpioArchiveEntry in the new format with CRC. FORMAT_ constants are internal. */
short FORMAT_NEW_CRC = 2;

/** Write/read a CpioArchiveEntry in the old ASCII format. FORMAT_ constants are internal. */
short FORMAT_OLD_ASCII = 4;

/** Write/read a CpioArchiveEntry in the old binary format. FORMAT_ constants are internal. */
short FORMAT_OLD_BINARY = 8;

/** Write/read a CpioArchiveEntry in the stripped format. FORMAT_ constants are internal. */
short FORMAT_STRIPPED = 16;

/** Mask for both new formats. FORMAT_ constants are internal. */
short FORMAT_NEW_MASK = 3;

/** Mask for both old formats. FORMAT_ constants are internal. */
short FORMAT_OLD_MASK = 12;

/*
* Constants for the MODE bits
*/

/** Mask for all file type bits. */
int S_IFMT = 0170000;

/** Defines a socket */
int C_ISSOCK = 0140000;

/** Defines a symbolic link */
int C_ISLNK = 0120000;

/** HP/UX network special (C_ISCTG) */
int C_ISNWK = 0110000;

/** Defines a regular file */
int C_ISREG = 0100000;

/** Defines a block device */
int C_ISBLK = 0060000;

/** Defines a directory */
int C_ISDIR = 0040000;

/** Defines a character device */
int C_ISCHR = 0020000;

/** Defines a pipe */
int C_ISFIFO = 0010000;

/** Sets user ID */
int C_ISUID = 0004000;

/** Sets group ID */
int C_ISGID = 0002000;

/** On directories, restricted deletion flag. */
int C_ISVTX = 0001000;

/** Permits the owner of a file to read the file */
int C_IRUSR = 0000400;

/** Permits the owner of a file to write to the file */
int C_IWUSR = 0000200;

/** Permits the owner of a file to execute the file or to search the directory */
int C_IXUSR = 0000100;

/** Permits a file's group to read the file */
int C_IRGRP = 0000040;

/** Permits a file's group to write to the file */
int C_IWGRP = 0000020;

/** Permits a file's group to execute the file or to search the directory */
int C_IXGRP = 0000010;

/** Permits others to read the file */
int C_IROTH = 0000004;

/** Permits others to write to the file */
int C_IWOTH = 0000002;

/** Permits others to execute the file or to search the directory */
int C_IXOTH = 0000001;

/** The special trailer marker */
String CPIO_TRAILER = "TRAILER!!!";

/**
* The default block size.
*
* @since 1.1
*/
int BLOCK_SIZE = 512;
}
50 changes: 50 additions & 0 deletions rpm/src/main/java/org/eclipse/packager/rpm/RpmFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2015, 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.packager.rpm;

public enum RpmFormat {
RPM_3(3),
RPM_4(4),
RPM_6(6);

public static final RpmFormat DEFAULT = RPM_4;

private final int format;

RpmFormat(final int format) {
this.format = format;
}

public int getFormat() {
return this.format;
}

public static RpmFormat fromFormat(final int format) {
switch (format) {
case 3:
return RPM_3;
case 4:
return RPM_4;
case 6:
return RPM_6;
default:
throw new IllegalArgumentException("Unknown RPM format: " + format);
}
}

@Override
public String toString() {
return String.valueOf(this.format);
}
}
31 changes: 28 additions & 3 deletions rpm/src/main/java/org/eclipse/packager/rpm/RpmTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import java.util.Map;

public enum RpmTag implements RpmBaseTag {
HEADER_SIGNATURES(62, byte[].class),
HEADER_IMMUTABLE(63, byte[].class),
HEADER_I18NTABLE(100, String.class),
NAME(1000, String.class),
VERSION(1001, String.class),
RELEASE(1002, String.class),
Expand Down Expand Up @@ -94,6 +97,10 @@ public enum RpmTag implements RpmBaseTag {
POSTTRANSACTION_SCRIPT(1152, String.class),
PRETRANSACTION_SCRIPT_PROG(1153, String[].class),
POSTTRANSACTION_SCRIPT_PROG(1154, String[].class),
/**
* File size (when files &gt; 4GB are present). Always used in RPM 6.
*/
LONG_FILE_SIZES(5008, Long[].class),
LONGSIZE(5009, Long.class),
FILE_DIGESTALGO(5011, Integer.class),
RECOMMEND_NAME(5046, String[].class),
Expand All @@ -108,16 +115,34 @@ public enum RpmTag implements RpmBaseTag {
ENHANCE_NAME(5055, String[].class),
ENHANCE_VERSION(5056, String[].class),
ENHANCE_FLAGS(5057, Integer[].class),
/**
* Encoding of the header string data. When present it is always "utf-8" and the data has actually been validated.
* Always present in RPM 6.
*/
ENCODING(5062, String.class),

PAYLOAD_DIGEST(5092, String[].class),
PAYLOAD_DIGEST_ALGO(5093, Integer.class),
PAYLOAD_DIGEST_ALT(5097, String[].class);
PAYLOAD_DIGEST_ALT(5097, String[].class),

/**
* The compressed payload size.
*/
PAYLOAD_SIZE(5112, Long.class),
/**
* The uncompressed payload size.
*/
PAYLOAD_SIZE_ALT(5113, Long.class),
/**
* The RPM version number (version 6 or later).
*/
RPM_FORMAT(5114, Integer.class);

private final Integer value;

private final Class<?> dataType;

<T> RpmTag(final Integer value, Class<T> dataType) {
<T> RpmTag(final Integer value, final Class<T> dataType) {
this.value = value;
this.dataType = dataType;
}
Expand Down Expand Up @@ -145,7 +170,7 @@ public static RpmTag find(final Integer value) {

@Override
public String toString() {
RpmTag tag = find(this.value);
final RpmTag tag = find(this.value);
return dataType.getSimpleName() + " " + (tag != null ? tag.name() + "(" + this.value + ")" : "UNKNOWN(" + this.value + ")");
}
}
4 changes: 2 additions & 2 deletions rpm/src/main/java/org/eclipse/packager/rpm/Rpms.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class Rpms {

public static final byte[] EMPTY_128;

public static final int IMMUTABLE_TAG_SIGNATURE = 62;
public static final int IMMUTABLE_TAG_SIGNATURE = RpmTag.HEADER_SIGNATURES.getValue();

public static final int IMMUTABLE_TAG_HEADER = 63;
public static final int IMMUTABLE_TAG_HEADER = RpmTag.HEADER_IMMUTABLE.getValue();

static {
EMPTY_128 = new byte[128];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.LinkedList;
import java.util.List;

import org.eclipse.packager.rpm.RpmFormat;
import org.eclipse.packager.rpm.coding.PayloadCoding;
import org.eclipse.packager.rpm.coding.PayloadFlags;

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

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

private int rpmFormat = RpmFormat.DEFAULT.getFormat();

private LongMode longMode = LongMode.DEFAULT;

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

public BuilderOptions(final BuilderOptions other) {
setRpmFormat(other.rpmFormat);
setLongMode(other.longMode);
setOpenOptions(other.openOptions);
setFileNameProvider(other.fileNameProvider);
Expand All @@ -74,6 +77,18 @@ public BuilderOptions(final BuilderOptions other) {
setPayloadProcessors(other.payloadProcessors);
}

public int getRpmFormat() {
return this.rpmFormat;
}

public void setRpmFormat(final int rpmFormat) {
this.rpmFormat = RpmFormat.fromFormat(rpmFormat).getFormat();

if (this.rpmFormat >= 6) {
this.payloadProcessors.add(PayloadProcessors.payloadSize());
}
}

public LongMode getLongMode() {
return this.longMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,53 @@ private PayloadProcessors() {
}

/**
* Create the payload digest values for @{link {@link RpmTag#PAYLOAD_DIGEST}
* and @{link
* {@link RpmTag#PAYLOAD_DIGEST_ALT}}
* Create the payload size values for @{link {@link RpmTag#PAYLOAD_SIZE} and {@link RpmTag#PAYLOAD_SIZE_ALT}}.
*
* @param algorithm The digest algorithm to use.
* @return the payload processor
*/
public static PayloadProcessor payloadSize() {
return new PayloadProcessor() {
private long payloadSize;

private long archiveSize;

@Override
public void feedRawPayloadData(final ByteBuffer data) {
payloadSize += data.remaining();
}

@Override
public void feedCompressedPayloadData(final ByteBuffer data) {
archiveSize += data.remaining();
}

@Override
public void finish(final Header<RpmTag> header) {
header.putLong(RpmTag.PAYLOAD_SIZE, payloadSize);
header.putLong(RpmTag.PAYLOAD_SIZE_ALT, archiveSize);
}
};
}

/**
* Create the payload digest values for @{link {@link RpmTag#PAYLOAD_DIGEST} and {@link RpmTag#PAYLOAD_DIGEST_ALT}}.
*
* @param algorithm The digest algorithm to use
* @return The payload processor
* @throws NoSuchAlgorithmException In case the algorithm isn't supported by the
* JVM.
* @throws NoSuchAlgorithmException In case the algorithm isn't supported by the JVM
*/
public static PayloadProcessor payloadDigest(final DigestAlgorithm algorithm) throws NoSuchAlgorithmException {
final MessageDigest digestRaw = algorithm.createDigest();
final MessageDigest digestCompressed = algorithm.createDigest();

return new PayloadProcessor() {

@Override
public void feedRawPayloadData(ByteBuffer data) {
public void feedRawPayloadData(final ByteBuffer data) {
digestRaw.update(data);
}

@Override
public void feedCompressedPayloadData(ByteBuffer data) {
public void feedCompressedPayloadData(final ByteBuffer data) {
digestCompressed.update(data);
}

Expand All @@ -62,5 +87,4 @@ public void finish(final Header<RpmTag> header) {
}
};
}

}
Loading