< prev index next >
src/java.base/share/classes/java/util/zip/ZipEntry.java
Print this page
rev 51866 : 6194856: Zip Files lose ALL ownership and permissions of the files
*** 1,7 ****
/*
! * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 23,41 ****
* questions.
*/
package java.util.zip;
import static java.util.zip.ZipUtils.*;
import java.nio.file.attribute.FileTime;
! import java.util.Objects;
! import java.util.concurrent.TimeUnit;
import java.time.LocalDateTime;
- import java.time.ZonedDateTime;
import java.time.ZoneId;
!
! import static java.util.zip.ZipConstants64.*;
/**
* This class is used to represent a ZIP file entry.
*
* @author David Connelly
--- 23,45 ----
* questions.
*/
package java.util.zip;
+ import static java.util.zip.ZipConstants64.*;
import static java.util.zip.ZipUtils.*;
+
import java.nio.file.attribute.FileTime;
! import java.nio.file.attribute.PosixFilePermission;
! import java.nio.file.attribute.PosixFilePermissions;
import java.time.LocalDateTime;
import java.time.ZoneId;
! import java.time.ZonedDateTime;
! import java.util.Objects;
! import java.util.Optional;
! import java.util.Set;
! import java.util.concurrent.TimeUnit;
/**
* This class is used to represent a ZIP file entry.
*
* @author David Connelly
*** 54,63 ****
--- 58,68 ----
long crc = -1; // crc-32 of entry data
long size = -1; // uncompressed size of entry data
long csize = -1; // compressed size of entry data
int method = -1; // compression method
int flag = 0; // general purpose flag
+ int posixPerms = -1; // posix permissions
byte[] extra; // optional extra field data for entry
String comment; // optional comment string for entry
/**
* Compression method for uncompressed entries.
*** 654,663 ****
--- 659,705 ----
public boolean isDirectory() {
return name.endsWith("/");
}
/**
+ * Returns the set of Posix file permissions that are associated with
+ * this ZipEntry. This information might not be present all times,
+ * e.g. it is platform dependend. Also, when reading a zip file via
+ * {@link ZipInputStream}, the posix permissions will be null
+ * because data is stored in the CEN of the zip file which is not
+ * evaluated then. If you rely on Posix permissions, you need to access
+ * the zip file via {@link ZipFile}.
+ *
+ * @return The set of Posix File permissions, in case they are associated.
+ *
+ * @since 12
+ */
+ public Optional<Set<PosixFilePermission>> getPosixPermissions() {
+ if (posixPerms == -1) {
+ return Optional.empty();
+ }
+ return Optional.of(PosixFilePermissions.fromFlags(posixPerms));
+ }
+
+ /**
+ * Sets the set of Posix file permissions for this ZipEntry.
+ *
+ * @param permissions A set of PosixFilePermissions. If the value is null,
+ * no permission information will be stored in the zip
+ * file.
+ *
+ * @since 12
+ */
+ public void setPosixPermissions(Set<PosixFilePermission> permissions) {
+ if (permissions == null) {
+ posixPerms = -1;
+ return;
+ }
+ posixPerms = PosixFilePermissions.toFlags(permissions);
+ }
+
+ /**
* Returns a string representation of the ZIP entry.
*/
public String toString() {
return getName();
}
< prev index next >