HADOOP-9723. Improve error message when hadoop archive output path already exists. Contributed by Jean-Baptiste Onofré and Yongjun Zhang.
This commit is contained in:
parent
e82067bfe6
commit
92c38e41e1
@ -560,6 +560,9 @@ Release 2.8.0 - UNRELEASED
|
||||
HADOOP-11948. test-patch's issue matching regex should be configurable.
|
||||
(Sean Busbey via aw)
|
||||
|
||||
HADOOP-9723. Improve error message when hadoop archive output path already
|
||||
exists. (Jean-Baptiste Onofré and Yongjun Zhang via aajisak)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
HADOOP-11785. Reduce the number of listStatus operation in distcp
|
||||
|
@ -469,8 +469,13 @@ void archive(Path parentPath, List<Path> srcPaths,
|
||||
Path outputPath = new Path(dest, archiveName);
|
||||
FileOutputFormat.setOutputPath(conf, outputPath);
|
||||
FileSystem outFs = outputPath.getFileSystem(conf);
|
||||
if (outFs.exists(outputPath) || outFs.isFile(dest)) {
|
||||
throw new IOException("Invalid Output: " + outputPath);
|
||||
if (outFs.exists(outputPath)) {
|
||||
throw new IOException("Archive path: "
|
||||
+ outputPath.toString() + " already exists");
|
||||
}
|
||||
if (outFs.isFile(dest)) {
|
||||
throw new IOException("Destination " + dest.toString()
|
||||
+ " should be a directory but is a file");
|
||||
}
|
||||
conf.set(DST_DIR_LABEL, outputPath.toString());
|
||||
Path stagingArea;
|
||||
@ -846,8 +851,8 @@ public int run(String[] args) throws Exception {
|
||||
Path argPath = new Path(args[i]);
|
||||
if (argPath.isAbsolute()) {
|
||||
System.out.println(usage);
|
||||
throw new IOException("source path " + argPath +
|
||||
" is not relative to "+ parentPath);
|
||||
throw new IOException("Source path " + argPath +
|
||||
" is not relative to "+ parentPath);
|
||||
}
|
||||
srcPaths.add(new Path(parentPath, argPath));
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
@ -175,8 +176,47 @@ public void testRelativePathWitRepl() throws Exception {
|
||||
final List<String> harPaths = lsr(shell, fullHarPathStr);
|
||||
Assert.assertEquals(originalPaths, harPaths);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void testOutputPathValidity() throws Exception {
|
||||
final String inputPathStr = inputPath.toUri().getPath();
|
||||
final URI uri = fs.getUri();
|
||||
final String harName = "foo.har";
|
||||
System.setProperty(HadoopArchives.TEST_HADOOP_ARCHIVES_JAR_PATH,
|
||||
HADOOP_ARCHIVES_JAR);
|
||||
final HadoopArchives har = new HadoopArchives(conf);
|
||||
|
||||
PrintStream stderr = System.err;
|
||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||
PrintStream newErr = new PrintStream(byteStream);
|
||||
System.setErr(newErr);
|
||||
|
||||
// fail if the archive path already exists
|
||||
createFile(archivePath, fs, harName);
|
||||
final String[] args = { "-archiveName", harName, "-p", inputPathStr, "*",
|
||||
archivePath.toString() };
|
||||
Assert.assertEquals(-1, ToolRunner.run(har, args));
|
||||
String output = byteStream.toString();
|
||||
final Path outputPath = new Path(archivePath, harName);
|
||||
Assert.assertTrue(output.indexOf("Archive path: " + outputPath.toString()
|
||||
+ " already exists") != -1);
|
||||
|
||||
byteStream.reset();
|
||||
|
||||
// fail if the destination directory is a file
|
||||
createFile(archivePath, fs, "sub1");
|
||||
final Path archivePath2 = new Path(archivePath, "sub1");
|
||||
final String[] args2 = { "-archiveName", harName, "-p", inputPathStr, "*",
|
||||
archivePath2.toString() };
|
||||
Assert.assertEquals(-1, ToolRunner.run(har, args2));
|
||||
output = byteStream.toString();
|
||||
Assert.assertTrue(output.indexOf("Destination " + archivePath2.toString()
|
||||
+ " should be a directory but is a file") != -1);
|
||||
|
||||
System.setErr(stderr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathWithSpaces() throws Exception {
|
||||
// create files/directories with spaces
|
||||
createFile(inputPath, fs, "c c");
|
||||
|
Loading…
Reference in New Issue
Block a user