Jelajahi Sumber

commit 54da3daaee69eae19dc09af62bb7cd1f32f78f12
Author: Devaraj Das <ddas@yahoo-inc.com>
Date: Mon Sep 20 14:25:31 2010 -0700

Fixes delete in the CleanupQueue to do the delete as the login user


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-patches@1077717 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 tahun lalu
induk
melakukan
d532add62f

+ 11 - 2
src/mapred/org/apache/hadoop/mapred/CleanupQueue.java

@@ -19,6 +19,7 @@
 package org.apache.hadoop.mapred;
 
 import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
 import java.util.concurrent.LinkedBlockingQueue;
 
 import org.apache.commons.logging.Log;
@@ -26,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.security.UserGroupInformation;
 
 class CleanupQueue {
 
@@ -66,10 +68,17 @@ class CleanupQueue {
 
     /**
      * Deletes the path (and its subdirectories recursively)
+     * @throws IOException, InterruptedException 
      */
-    protected void deletePath() throws IOException {
+    protected void deletePath() throws IOException, InterruptedException {
       final Path p = getPathForCleanup();
-      p.getFileSystem(conf).delete(p, true);
+      UserGroupInformation.getLoginUser().doAs(
+          new PrivilegedExceptionAction<Object>() {
+            public Object run() throws IOException {
+             p.getFileSystem(conf).delete(p, true);
+             return null;
+            }
+          });
     }
 
     @Override

+ 9 - 2
src/test/org/apache/hadoop/mapred/UtilsForTests.java

@@ -451,20 +451,27 @@ public class UtilsForTests {
     public void addToQueue(PathDeletionContext... contexts) {
       // delete paths in-line
       for (PathDeletionContext context : contexts) {
+        Exception exc = null;
         try {
           if (!deletePath(context)) {
             LOG.warn("Stale path " + context.fullPath);
             stalePaths.add(context.fullPath);
           }
         } catch (IOException e) {
+          exc = e;
+        } catch (InterruptedException ie) {
+          exc = ie;
+        }
+        if (exc != null) {
           LOG.warn("Caught exception while deleting path "
               + context.fullPath);
-          LOG.info(StringUtils.stringifyException(e));
+          LOG.info(StringUtils.stringifyException(exc));
           stalePaths.add(context.fullPath);
         }
       }
     }
-    static boolean deletePath(PathDeletionContext context) throws IOException {
+    static boolean deletePath(PathDeletionContext context) 
+    throws IOException, InterruptedException {
       if (LOG.isDebugEnabled()) {
         LOG.debug("Trying to delete " + context.fullPath);
       }