This is an automated email from the ASF dual-hosted git repository.
stevel pushed a commit to branch branch-3.3.2
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.3.2 by this push:
new 7f33a4e HADOOP-18136. Verify FileUtils.unTar() handling of missing
.tar files.
7f33a4e is described below
commit 7f33a4e99205ea8c14e1c9e50797a5dd3818fe8b
Author: Steve Loughran <[email protected]>
AuthorDate: Mon Feb 21 17:08:22 2022 +0000
HADOOP-18136. Verify FileUtils.unTar() handling of missing .tar files.
Contributed by Steve Loughran
Change-Id: I3856afa821dbc8c2e3cb1cbe33793ec1734e2e24
---
.../main/java/org/apache/hadoop/fs/FileUtil.java | 15 ++++++----
.../java/org/apache/hadoop/fs/TestFileUtil.java | 33 ++++++++++++++++++++++
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
index 82ad513..5e2d6c5 100644
---
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
+++
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
@@ -887,10 +887,13 @@ public class FileUtil {
private static void unTarUsingTar(File inFile, File untarDir,
boolean gzipped) throws IOException {
StringBuffer untarCommand = new StringBuffer();
+ // not using canonical path here; this postpones relative path
+ // resolution until bash is executed.
+ final String source = "'" + FileUtil.makeSecureShellPath(inFile) + "'";
if (gzipped) {
- untarCommand.append(" gzip -dc '")
- .append(FileUtil.makeSecureShellPath(inFile))
- .append("' | (");
+ untarCommand.append(" gzip -dc ")
+ .append(source)
+ .append(" | (");
}
untarCommand.append("cd '")
.append(FileUtil.makeSecureShellPath(untarDir))
@@ -900,15 +903,17 @@ public class FileUtil {
if (gzipped) {
untarCommand.append(" -)");
} else {
- untarCommand.append(FileUtil.makeSecureShellPath(inFile));
+ untarCommand.append(source);
}
+ LOG.debug("executing [{}]", untarCommand);
String[] shellCmd = { "bash", "-c", untarCommand.toString() };
ShellCommandExecutor shexec = new ShellCommandExecutor(shellCmd);
shexec.execute();
int exitcode = shexec.getExitCode();
if (exitcode != 0) {
throw new IOException("Error untarring file " + inFile +
- ". Tar process exited with exit code " + exitcode);
+ ". Tar process exited with exit code " + exitcode
+ + " from command " + untarCommand);
}
}
diff --git
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java
index 1ca1f24..e84d23c 100644
---
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java
+++
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.fs;
+import static org.apache.hadoop.test.LambdaTestUtils.intercept;
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -1106,6 +1107,38 @@ public class TestFileUtil {
doUntarAndVerify(new File(tarFileName), untarDir);
}
+ /**
+ * Verify we can't unTar a file which isn't there.
+ * This will test different codepaths on Windows from unix,
+ * but both MUST throw an IOE of some kind.
+ */
+ @Test(timeout = 30000)
+ public void testUntarMissingFile() throws Throwable {
+ File dataDir = GenericTestUtils.getTestDir();
+ File tarFile = new File(dataDir, "missing; true");
+ File untarDir = new File(dataDir, "untarDir");
+ intercept(IOException.class, () ->
+ FileUtil.unTar(tarFile, untarDir));
+ }
+
+ /**
+ * Verify we can't unTar a file which isn't there
+ * through the java untar code.
+ * This is how {@code FileUtil.unTar(File, File}
+ * will behave on Windows,
+ */
+ @Test(timeout = 30000)
+ public void testUntarMissingFileThroughJava() throws Throwable {
+ File dataDir = GenericTestUtils.getTestDir();
+ File tarFile = new File(dataDir, "missing; true");
+ File untarDir = new File(dataDir, "untarDir");
+ // java8 on unix throws java.nio.file.NoSuchFileException here;
+ // leaving as an IOE intercept in case windows throws something
+ // else.
+ intercept(IOException.class, () ->
+ FileUtil.unTarUsingJava(tarFile, untarDir, false));
+ }
+
@Test (timeout = 30000)
public void testCreateJarWithClassPath() throws Exception {
// create files expected to match a wildcard
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]