< prev index next >

src/jdk.jartool/share/classes/sun/tools/jar/Main.java

Print this page
rev 51866 : 6194856: Zip Files lose ALL ownership and permissions of the files

*** 1,7 **** /* ! * Copyright (c) 1996, 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) 1996, 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,32 **** --- 23,37 ---- * questions. */ package sun.tools.jar; + import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; + import static java.util.jar.JarFile.MANIFEST_NAME; + import static java.util.stream.Collectors.joining; + import static jdk.internal.util.jar.JarIndex.INDEX_NAME; + import java.io.*; import java.lang.module.Configuration; import java.lang.module.FindException; import java.lang.module.InvalidModuleDescriptorException; import java.lang.module.ModuleDescriptor;
*** 42,51 **** --- 47,57 ---- import java.nio.ByteBuffer; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; + import java.nio.file.attribute.PosixFilePermission; import java.text.MessageFormat; import java.util.*; import java.util.function.Consumer; import java.util.jar.Attributes; import java.util.jar.JarFile;
*** 57,80 **** import java.util.zip.CRC32; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; import jdk.internal.module.Checks; import jdk.internal.module.ModuleHashes; import jdk.internal.module.ModuleHashesBuilder; import jdk.internal.module.ModuleInfo; import jdk.internal.module.ModuleInfoExtender; import jdk.internal.module.ModuleResolution; import jdk.internal.module.ModuleTarget; import jdk.internal.util.jar.JarIndex; - import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; - import static java.util.jar.JarFile.MANIFEST_NAME; - import static java.util.stream.Collectors.joining; - import static jdk.internal.util.jar.JarIndex.INDEX_NAME; - /** * This class implements a simple utility for creating files in the JAR * (Java Archive) file format. The JAR format is based on the ZIP file * format, with optional meta-information stored in a MANIFEST entry. */ --- 63,82 ---- import java.util.zip.CRC32; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; + import jdk.internal.module.Checks; import jdk.internal.module.ModuleHashes; import jdk.internal.module.ModuleHashesBuilder; import jdk.internal.module.ModuleInfo; import jdk.internal.module.ModuleInfoExtender; import jdk.internal.module.ModuleResolution; import jdk.internal.module.ModuleTarget; import jdk.internal.util.jar.JarIndex; /** * This class implements a simple utility for creating files in the JAR * (Java Archive) file format. The JAR format is based on the ZIP file * format, with optional meta-information stored in a MANIFEST entry. */
*** 147,158 **** * Mflag: DO NOT generate a manifest file (just ZIP) * iflag: generate jar index * nflag: Perform jar normalization at the end * pflag: preserve/don't strip leading slash and .. component from file name * dflag: print module descriptor */ ! boolean cflag, uflag, xflag, tflag, vflag, flag0, Mflag, iflag, nflag, pflag, dflag; boolean suppressDeprecateMsg = false; /* To support additional GNU Style informational options */ Consumer<PrintWriter> info; --- 149,161 ---- * Mflag: DO NOT generate a manifest file (just ZIP) * iflag: generate jar index * nflag: Perform jar normalization at the end * pflag: preserve/don't strip leading slash and .. component from file name * dflag: print module descriptor + * oflag: preserve Posix file attributes */ ! boolean cflag, uflag, xflag, tflag, vflag, flag0, Mflag, iflag, nflag, pflag, dflag, oflag; boolean suppressDeprecateMsg = false; /* To support additional GNU Style informational options */ Consumer<PrintWriter> info;
*** 397,407 **** // "leading garbage", we fall back from the ZipInputStream // implementation to the ZipFile implementation, since only the // latter can handle it. String[] files = filesMapToFiles(filesMap); ! if (fname != null && files != null) { extract(fname, files); } else { InputStream in = (fname == null) ? new FileInputStream(FileDescriptor.in) : new FileInputStream(fname); --- 400,413 ---- // "leading garbage", we fall back from the ZipInputStream // implementation to the ZipFile implementation, since only the // latter can handle it. String[] files = filesMapToFiles(filesMap); ! // if we need to restore posix permissions (-o flag), we need to use ! // the ZipFile approach because permissions are stored in the CEN ! // which is not read when using a ZipInputStream. ! if (fname != null && (files != null || oflag)) { extract(fname, files); } else { InputStream in = (fname == null) ? new FileInputStream(FileDescriptor.in) : new FileInputStream(fname);
*** 1204,1213 **** --- 1210,1222 ---- e.setSize(0); e.setCrc(0); } else if (flag0) { crc32File(e, file); } + if (oflag) { + e.setPosixPermissions(Files.getPosixFilePermissions(file.toPath())); + } zos.putNextEntry(e); if (!isDir) { copy(file, zos); } zos.closeEntry();
*** 1470,1479 **** --- 1479,1498 ---- long lastModified = e.getTime(); if (lastModified != -1) { f.setLastModified(lastModified); } } + if (oflag) { + Optional<Set<PosixFilePermission>> permissions = e.getPosixPermissions(); + if (permissions.isPresent()) { + try { + Files.setPosixFilePermissions(f.toPath(), permissions.get()); + } catch (UnsupportedOperationException exc) { + // Ignore the exception + } + } + } return rc; } /** * Lists contents of JAR file.
< prev index next >