HADOOP-11179. Java untar should handle the case that the file entry comes without its parent directory entry. Contributed by Craig Welch.
(cherry picked from commit a169051931
)
This commit is contained in:
parent
204148f0d4
commit
ab448565c9
|
@ -591,6 +591,9 @@ Release 2.6.0 - UNRELEASED
|
||||||
HADOOP-11163. MetricsSystemImpl may miss a registered source.
|
HADOOP-11163. MetricsSystemImpl may miss a registered source.
|
||||||
(Chuan Liu via cnauroth)
|
(Chuan Liu via cnauroth)
|
||||||
|
|
||||||
|
HADOOP-11179. Java untar should handle the case that the file entry comes
|
||||||
|
without its parent directory entry. (Craig Welch via zjshen)
|
||||||
|
|
||||||
Release 2.5.1 - 2014-09-05
|
Release 2.5.1 - 2014-09-05
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -707,7 +707,7 @@ public class FileUtil {
|
||||||
TarArchiveEntry entry, File outputDir) throws IOException {
|
TarArchiveEntry entry, File outputDir) throws IOException {
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
File subDir = new File(outputDir, entry.getName());
|
File subDir = new File(outputDir, entry.getName());
|
||||||
if (!subDir.mkdir() && !subDir.isDirectory()) {
|
if (!subDir.mkdirs() && !subDir.isDirectory()) {
|
||||||
throw new IOException("Mkdirs failed to create tar internal dir "
|
throw new IOException("Mkdirs failed to create tar internal dir "
|
||||||
+ outputDir);
|
+ outputDir);
|
||||||
}
|
}
|
||||||
|
@ -720,8 +720,8 @@ public class FileUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
File outputFile = new File(outputDir, entry.getName());
|
File outputFile = new File(outputDir, entry.getName());
|
||||||
if (!outputDir.exists()) {
|
if (!outputFile.getParentFile().exists()) {
|
||||||
if (!outputDir.mkdirs()) {
|
if (!outputFile.getParentFile().mkdirs()) {
|
||||||
throw new IOException("Mkdirs failed to create tar internal dir "
|
throw new IOException("Mkdirs failed to create tar internal dir "
|
||||||
+ outputDir);
|
+ outputDir);
|
||||||
}
|
}
|
||||||
|
|
|
@ -619,7 +619,7 @@ public class TestFileUtil {
|
||||||
OutputStream os = new FileOutputStream(simpleTar);
|
OutputStream os = new FileOutputStream(simpleTar);
|
||||||
TarOutputStream tos = new TarOutputStream(os);
|
TarOutputStream tos = new TarOutputStream(os);
|
||||||
try {
|
try {
|
||||||
TarEntry te = new TarEntry("foo");
|
TarEntry te = new TarEntry("/bar/foo");
|
||||||
byte[] data = "some-content".getBytes("UTF-8");
|
byte[] data = "some-content".getBytes("UTF-8");
|
||||||
te.setSize(data.length);
|
te.setSize(data.length);
|
||||||
tos.putNextEntry(te);
|
tos.putNextEntry(te);
|
||||||
|
@ -634,8 +634,8 @@ public class TestFileUtil {
|
||||||
// successfully untar it into an existing dir:
|
// successfully untar it into an existing dir:
|
||||||
FileUtil.unTar(simpleTar, tmp);
|
FileUtil.unTar(simpleTar, tmp);
|
||||||
// check result:
|
// check result:
|
||||||
assertTrue(new File(tmp, "foo").exists());
|
assertTrue(new File(tmp, "/bar/foo").exists());
|
||||||
assertEquals(12, new File(tmp, "foo").length());
|
assertEquals(12, new File(tmp, "/bar/foo").length());
|
||||||
|
|
||||||
final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");
|
final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");
|
||||||
regularFile.createNewFile();
|
regularFile.createNewFile();
|
||||||
|
|
Loading…
Reference in New Issue