Browse Source

HADOOP-301. In RandomWriter example, don't overwrite output directory
if it already exists. Contributed by Owen.


git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@417270 13f79535-47bb-0310-9956-ffa450edef68

Doug Cutting 19 years ago
parent
commit
7ef669812e
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/examples/org/apache/hadoop/examples/RandomWriter.java

+ 5 - 1
src/examples/org/apache/hadoop/examples/RandomWriter.java

@@ -177,8 +177,12 @@ public class RandomWriter extends MapReduceBase implements Reducer {
     Path inDir = new Path(tmpDir, "in");
     Path fakeOutDir = new Path(tmpDir, "out");
     FileSystem fileSys = FileSystem.get(jobConf);
+    if (fileSys.exists(outDir)) {
+      System.out.println("Error: Output directory " + outDir + 
+                         " already exists.");
+      return;
+    }
     fileSys.delete(tmpDir);
-    fileSys.delete(outDir);
     fileSys.mkdirs(inDir);
     NumberFormat numberFormat = NumberFormat.getInstance();
     numberFormat.setMinimumIntegerDigits(6);