From ca4d967a798d50e46a5749f607dfcef2cef89b9d Mon Sep 17 00:00:00 2001
From: Chad Metcalf <chad@cloudera.com>
Date: Mon, 14 Sep 2009 12:03:04 -0700
Subject: [PATCH] MAPREDUCE-968: NPE in distcp encountered when placing _logs directory on
 S3FileSystem (Chad Metcalf for Aaron Kimball)

---
 src/tools/org/apache/hadoop/tools/DistCp.java |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/tools/org/apache/hadoop/tools/DistCp.java b/src/tools/org/apache/hadoop/tools/DistCp.java
index b0eb2d1..04b4d06 100644
--- a/src/tools/org/apache/hadoop/tools/DistCp.java
+++ b/src/tools/org/apache/hadoop/tools/DistCp.java
@@ -1005,6 +1005,12 @@ public class DistCp implements Tool {
       String filename = "_distcp_logs_" + randomId;
       if (!dstExists || !dstIsDir) {
         Path parent = args.dst.getParent();
+        if (null == parent) {
+          // If dst is '/' on S3, it might not exist yet, but dst.getParent()
+          // will return null. In this case, use '/' as its own parent to prevent
+          // NPE errors below.
+          parent = args.dst;
+        }
         if (!dstfs.exists(parent)) {
           dstfs.mkdirs(parent);
         }
-- 
1.6.0.4

