HADOOP-16026:Replace incorrect use of system property user.name.

Contributed by Dinesh Chitlangia.
This commit is contained in:
Anu Engineer 2019-04-22 12:01:15 -07:00
parent a54c1e3ace
commit f4ab9370f5
2 changed files with 20 additions and 3 deletions

View File

@ -51,6 +51,7 @@
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.SecurityUtil; import org.apache.hadoop.security.SecurityUtil;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.util.LambdaUtils; import org.apache.hadoop.util.LambdaUtils;
import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.Progressable;
@ -456,8 +457,16 @@ public Path getInitialWorkingDirectory() {
* @return current user's home directory. * @return current user's home directory.
*/ */
public Path getHomeDirectory() { public Path getHomeDirectory() {
return new Path("/user/"+System.getProperty("user.name")).makeQualified( String username;
getUri(), null); try {
username = UserGroupInformation.getCurrentUser().getShortUserName();
} catch(IOException ex) {
LOG.warn("Unable to get user name. Fall back to system property " +
"user.name", ex);
username = System.getProperty("user.name");
}
return new Path("/user/" + username)
.makeQualified(getUri(), null);
} }
/** /**

View File

@ -2241,8 +2241,16 @@ public LocatedFileStatus next() throws IOException {
* The default implementation returns {@code "/user/$USER/"}. * The default implementation returns {@code "/user/$USER/"}.
*/ */
public Path getHomeDirectory() { public Path getHomeDirectory() {
String username;
try {
username = UserGroupInformation.getCurrentUser().getShortUserName();
} catch(IOException ex) {
LOGGER.warn("Unable to get user name. Fall back to system property " +
"user.name", ex);
username = System.getProperty("user.name");
}
return this.makeQualified( return this.makeQualified(
new Path(USER_HOME_PREFIX + "/" + System.getProperty("user.name"))); new Path(USER_HOME_PREFIX + "/" + username));
} }