From f89fc2c3670d9be67be69b2f39bdf83e7861411d Mon Sep 17 00:00:00 2001 From: rubensa Date: Fri, 7 Jul 2017 11:08:02 +0200 Subject: [PATCH] Preserve original file information for tar Looking for "bin" folder seems a bit "tricky" to me... For tar files we should keep original executable permissions as this info is available. For zip files executable information could be available for UNIX systems but in current ZipEntry implementation that info seems to be not available. --- core/ts.core/src/ts/utils/ZipUtils.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/ts.core/src/ts/utils/ZipUtils.java b/core/ts.core/src/ts/utils/ZipUtils.java index 1aa5d601..52bee783 100644 --- a/core/ts.core/src/ts/utils/ZipUtils.java +++ b/core/ts.core/src/ts/utils/ZipUtils.java @@ -102,6 +102,8 @@ public static void extractZip(File file, File destination) throws IOException { // Close the stream out.close(); + // Preserve original modification date + extracted.setLastModified(entry.getTime()); if (extracted.getParent().contains(BIN_FOLDER)) { extracted.setExecutable(true); } @@ -166,9 +168,13 @@ public static void extractTar(File file, File destination) throws IOException { // Close the stream out.close(); - if (extractedFile.getParent().contains(BIN_FOLDER)) { - extractedFile.setExecutable(true); - } + // Preserve original modification date + extractedFile.setLastModified(entry.getTime()); + long mode = entry.getMode(); + if ((mode & 00100) > 0) { + // Preserve execute permissions + extractedFile.setExecutable(true, (mode & 00001) == 0); + } break; case TarEntry.LINK: File linkFile = new File(destination, outFilename);