Procházet zdrojové kódy

HADOOP-2442. Fix TestLocalFileSystemPermission.testLocalFSsetOwner to work on more platforms. Contributed by Raghu Angadi.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@608301 13f79535-47bb-0310-9956-ffa450edef68
Nigel Daley před 17 roky
rodič
revize
e7eb339319

+ 3 - 0
CHANGES.txt

@@ -318,6 +318,9 @@ Trunk (unreleased changes)
     HADOOP-2511. Fix a javadoc warning in org.apache.hadoop.util.Shell
     introduced by HADOOP-2344. (acmurthy) 
 
+    HADOOP-2442. Fix TestLocalFileSystemPermission.testLocalFSsetOwner
+    to work on more platforms. (Raghu Angadi via nigel)
+
 Release 0.15.2 - 2008-01-02
 
   BUG FIXES

+ 8 - 5
src/java/org/apache/hadoop/fs/RawLocalFileSystem.java

@@ -389,7 +389,7 @@ public class RawLocalFileSystem extends FileSystem {
 
     @Override
     public String getGroup() {
-      if (isPermissionLoaded()) {
+      if (!isPermissionLoaded()) {
         loadPermissionInfo();
       }
       return super.getGroup();
@@ -447,10 +447,13 @@ public class RawLocalFileSystem extends FileSystem {
       throw new IOException("username == null && groupname == null");
     }
 
-    //[OWNER][:[GROUP]]
-    String s = (username == null? "": username)
-             + (groupname == null? "": ":" + groupname);
-    execCommand(pathToFile(p), Shell.SET_OWNER_COMMAND, s);
+    if (username == null) {
+      execCommand(pathToFile(p), Shell.SET_GROUP_COMMAND, groupname); 
+    } else {
+      //OWNER[:[GROUP]]
+      String s = username + (groupname == null? "": ":" + groupname);
+      execCommand(pathToFile(p), Shell.SET_OWNER_COMMAND, s);
+    }
   }
 
   /**

+ 7 - 1
src/java/org/apache/hadoop/util/Shell.java

@@ -47,11 +47,17 @@ abstract public class Shell {
   public static final String SET_PERMISSION_COMMAND = "chmod";
   /** a Unix command to set owner */
   public static final String SET_OWNER_COMMAND = "chown";
+  public static final String SET_GROUP_COMMAND = "chgrp";
   /** Return a Unix command to get permission information. */
   public static String[] getGET_PERMISSION_COMMAND() {
-    return new String[]{"ls", "-ld"};
+    //force /bin/ls, except on windows.
+    return new String[] {(WINDOWS ? "ls" : "/bin/ls"), "-ld"};
   }
 
+  /** Set to true on Windows platforms */
+  public static final boolean WINDOWS /* borrowed from Path.WINDOWS */
+                = System.getProperty("os.name").startsWith("Windows");
+  
   private long    interval;   // refresh interval in msec
   private long    lastTime;   // last time the command was performed
   private Map<String, String> environment; // env for the command execution

+ 12 - 7
src/test/org/apache/hadoop/fs/TestLocalFileSystemPermission.java

@@ -118,9 +118,9 @@ public class TestLocalFileSystemPermission extends TestCase {
       System.out.println("Cannot run test");
       return;
     }
-    if (groups == null || groups.size() < 2) {
-      System.out.println("Cannot run test: need at least two groups.  groups="
-          + groups);
+    if (groups == null || groups.size() < 1) {
+      System.out.println("Cannot run test: need at least one group.  groups="
+                         + groups);
       return;
     }
 
@@ -130,10 +130,15 @@ public class TestLocalFileSystemPermission extends TestCase {
       localfs.setOwner(f, null, g0);
       assertEquals(g0, getGroup(localfs, f));
 
-      String g1 = groups.get(1);
-      localfs.setOwner(f, null, g1);
-      assertEquals(g1, getGroup(localfs, f));
-    }
+      if (groups.size() > 1) {
+        String g1 = groups.get(1);
+        localfs.setOwner(f, null, g1);
+        assertEquals(g1, getGroup(localfs, f));
+      } else {
+        System.out.println("Not testing changing the group since user " +
+                           "belongs to only one group.");
+      }
+    } 
     finally {cleanupFile(localfs, f);}
   }