Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 03AC319E5A for ; Thu, 28 Apr 2016 18:02:04 +0000 (UTC) Received: (qmail 88168 invoked by uid 500); 28 Apr 2016 18:01:48 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 86216 invoked by uid 500); 28 Apr 2016 18:01:46 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 85226 invoked by uid 99); 28 Apr 2016 18:01:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Apr 2016 18:01:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4D715E0571; Thu, 28 Apr 2016 18:01:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: wangda@apache.org To: common-commits@hadoop.apache.org Date: Thu, 28 Apr 2016 18:02:12 -0000 Message-Id: In-Reply-To: <58f146a61c66461384583b583997bb9c@git.apache.org> References: <58f146a61c66461384583b583997bb9c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [28/50] [abbrv] hadoop git commit: HADOOP-5470. RunJar.unJar() should write the last modified time found in the jar entry to the uncompressed file. (Contributed by Andras Bakor) HADOOP-5470. RunJar.unJar() should write the last modified time found in the jar entry to the uncompressed file. (Contributed by Andras Bakor) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/3337ef2b Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/3337ef2b Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/3337ef2b Branch: refs/heads/YARN-3368 Commit: 3337ef2bfecb63f7f238ab72bbde62a0bbb4288d Parents: 185c3d4 Author: Arpit Agarwal Authored: Wed Apr 27 10:06:54 2016 -0700 Committer: Arpit Agarwal Committed: Wed Apr 27 10:06:54 2016 -0700 ---------------------------------------------------------------------- .../java/org/apache/hadoop/util/RunJar.java | 12 ++++++++++ .../java/org/apache/hadoop/util/TestRunJar.java | 23 ++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/3337ef2b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/RunJar.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/RunJar.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/RunJar.java index ccb114b..52cf05c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/RunJar.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/RunJar.java @@ -43,12 +43,16 @@ import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** Run a Hadoop job jar. */ @InterfaceAudience.Private @InterfaceStability.Unstable public class RunJar { + private static final Logger LOG = LoggerFactory.getLogger(RunJar.class); + /** Pattern that matches any string */ public static final Pattern MATCH_ANY = Pattern.compile(".*"); @@ -93,6 +97,7 @@ public class RunJar { throws IOException { JarFile jar = new JarFile(jarFile); try { + int numOfFailedLastModifiedSet = 0; Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); @@ -108,11 +113,18 @@ public class RunJar { } finally { out.close(); } + if (!file.setLastModified(entry.getTime())) { + numOfFailedLastModifiedSet++; + } } finally { in.close(); } } } + if (numOfFailedLastModifiedSet > 0) { + LOG.warn("Could not set last modfied time for {} file(s)", + numOfFailedLastModifiedSet); + } } finally { jar.close(); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/3337ef2b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java index 5b751e2..7262534 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java @@ -42,6 +42,8 @@ public class TestRunJar extends TestCase { private static final String TEST_JAR_NAME="test-runjar.jar"; private static final String TEST_JAR_2_NAME = "test-runjar2.jar"; + private static final long MOCKED_NOW = 1_460_389_972_000L; + private static final long MOCKED_NOW_PLUS_TWO_SEC = MOCKED_NOW + 2_000; @Override @Before @@ -68,9 +70,13 @@ public class TestRunJar extends TestCase { File jarFile = new File(TEST_ROOT_DIR, TEST_JAR_NAME); JarOutputStream jstream = new JarOutputStream(new FileOutputStream(jarFile)); - jstream.putNextEntry(new ZipEntry("foobar.txt")); + ZipEntry zipEntry1 = new ZipEntry("foobar.txt"); + zipEntry1.setTime(MOCKED_NOW); + jstream.putNextEntry(zipEntry1); jstream.closeEntry(); - jstream.putNextEntry(new ZipEntry("foobaz.txt")); + ZipEntry zipEntry2 = new ZipEntry("foobaz.txt"); + zipEntry2.setTime(MOCKED_NOW_PLUS_TWO_SEC); + jstream.putNextEntry(zipEntry2); jstream.closeEntry(); jstream.close(); } @@ -113,6 +119,19 @@ public class TestRunJar extends TestCase { } + public void testUnJarDoesNotLooseLastModify() throws Exception { + File unjarDir = new File(TEST_ROOT_DIR, "unjar-lastmod"); + assertFalse("unjar dir shouldn't exist at test start", + new File(unjarDir, "foobar.txt").exists()); + + // Unjar everything + RunJar.unJar(new File(TEST_ROOT_DIR, TEST_JAR_NAME), + unjarDir); + + assertEquals("Last modify time was lost during unJar", MOCKED_NOW, new File(unjarDir, "foobar.txt").lastModified()); + assertEquals("Last modify time was lost during unJar", MOCKED_NOW_PLUS_TWO_SEC, new File(unjarDir, "foobaz.txt").lastModified()); + } + /** * Tests the client classloader to verify the main class and its dependent * class are loaded correctly by the application classloader, and others are