mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8218021: Have jarsigner preserve posix permission attributes
Reviewed-by: weijun, lancea, alanb
This commit is contained in:
parent
dc63bf261b
commit
3d9bad16d1
14 changed files with 292 additions and 17 deletions
|
@ -57,7 +57,7 @@ public class ZipEntry implements ZipConstants, Cloneable {
|
|||
int flag = 0; // general purpose flag
|
||||
byte[] extra; // optional extra field data for entry
|
||||
String comment; // optional comment string for entry
|
||||
|
||||
int posixPerms = -1;// posix permissions
|
||||
/**
|
||||
* Compression method for uncompressed entries.
|
||||
*/
|
||||
|
@ -131,6 +131,7 @@ public class ZipEntry implements ZipConstants, Cloneable {
|
|||
flag = e.flag;
|
||||
extra = e.extra;
|
||||
comment = e.comment;
|
||||
posixPerms = e.posixPerms;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -657,6 +657,11 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||
e.size = CENLEN(cen, pos);
|
||||
e.csize = CENSIZ(cen, pos);
|
||||
e.method = CENHOW(cen, pos);
|
||||
if (CENVEM_FA(cen, pos) == FILE_ATTRIBUTES_UNIX) {
|
||||
// 12 bits for setuid, setgid, sticky + perms
|
||||
e.posixPerms = CENATX_PERMS(cen, pos) & 0xFFF;
|
||||
}
|
||||
|
||||
if (elen != 0) {
|
||||
int start = pos + CENHDR + nlen;
|
||||
e.setExtra0(Arrays.copyOfRange(cen, start, start + elen), true, false);
|
||||
|
@ -1092,6 +1097,16 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||
public Stream<String> entryNameStream(ZipFile zip) {
|
||||
return zip.entryNameStream();
|
||||
}
|
||||
// only set posix perms value via ZipEntry contructor for now
|
||||
@Override
|
||||
public int getPosixPerms(ZipEntry ze) {
|
||||
return ze.posixPerms;
|
||||
}
|
||||
@Override
|
||||
public void setPosixPerms(ZipEntry ze, int perms) {
|
||||
ze.posixPerms = perms;
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
isWindows = VM.getSavedProperty("os.name").contains("Windows");
|
||||
|
|
|
@ -506,6 +506,15 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds information about compatibility of file attribute information
|
||||
* to a version value.
|
||||
*/
|
||||
private int versionMadeBy(ZipEntry e, int version) {
|
||||
return (e.posixPerms < 0) ? version :
|
||||
VERSION_MADE_BY_BASE_UNIX | (version & 0xff);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write central directory (CEN) header for specified entry.
|
||||
* REMIND: add support for file attributes
|
||||
|
@ -537,10 +546,10 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
|
|||
}
|
||||
writeInt(CENSIG); // CEN header signature
|
||||
if (hasZip64) {
|
||||
writeShort(45); // ver 4.5 for zip64
|
||||
writeShort(versionMadeBy(e,45)); // ver 4.5 for zip64
|
||||
writeShort(45);
|
||||
} else {
|
||||
writeShort(version); // version made by
|
||||
writeShort(versionMadeBy(e, version)); // version made by
|
||||
writeShort(version); // version needed to extract
|
||||
}
|
||||
writeShort(flag); // general purpose bit flag
|
||||
|
@ -597,7 +606,8 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant
|
|||
}
|
||||
writeShort(0); // starting disk number
|
||||
writeShort(0); // internal file attributes (unused)
|
||||
writeInt(0); // external file attributes (unused)
|
||||
// external file attributes, used for storing posix permissions
|
||||
writeInt(e.posixPerms > 0 ? e.posixPerms << 16 : 0);
|
||||
writeInt(offset); // relative offset of local header
|
||||
writeBytes(nameBytes, 0, nameBytes.length);
|
||||
|
||||
|
|
|
@ -215,6 +215,17 @@ class ZipUtils {
|
|||
return LG(b, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* File attribute compatibility types of CEN field "version made by"
|
||||
*/
|
||||
static final int FILE_ATTRIBUTES_UNIX = 3; // Unix
|
||||
|
||||
/*
|
||||
* Base values for CEN field "version made by"
|
||||
*/
|
||||
static final int VERSION_MADE_BY_BASE_UNIX = FILE_ATTRIBUTES_UNIX << 8; // Unix
|
||||
|
||||
|
||||
// local file (LOC) header fields
|
||||
static final long LOCSIG(byte[] b) { return LG(b, 0); } // signature
|
||||
static final int LOCVER(byte[] b) { return SH(b, 4); } // version needed to extract
|
||||
|
@ -250,6 +261,7 @@ class ZipUtils {
|
|||
// central directory header (CEN) fields
|
||||
static final long CENSIG(byte[] b, int pos) { return LG(b, pos + 0); }
|
||||
static final int CENVEM(byte[] b, int pos) { return SH(b, pos + 4); }
|
||||
static final int CENVEM_FA(byte[] b, int pos) { return CH(b, pos + 5); } // file attribute compatibility
|
||||
static final int CENVER(byte[] b, int pos) { return SH(b, pos + 6); }
|
||||
static final int CENFLG(byte[] b, int pos) { return SH(b, pos + 8); }
|
||||
static final int CENHOW(byte[] b, int pos) { return SH(b, pos + 10);}
|
||||
|
@ -263,6 +275,7 @@ class ZipUtils {
|
|||
static final int CENDSK(byte[] b, int pos) { return SH(b, pos + 34);}
|
||||
static final int CENATT(byte[] b, int pos) { return SH(b, pos + 36);}
|
||||
static final long CENATX(byte[] b, int pos) { return LG(b, pos + 38);}
|
||||
static final int CENATX_PERMS(byte[] b, int pos) { return SH(b, pos + 40);} // posix permission data
|
||||
static final long CENOFF(byte[] b, int pos) { return LG(b, pos + 42);}
|
||||
|
||||
// The END header is followed by a variable length comment of size < 64k.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue