HADOOP-16026:Replace incorrect use of system property user.name.
Contributed by Dinesh Chitlangia.
This commit is contained in:
parent
a54c1e3ace
commit
f4ab9370f5
|
@ -51,6 +51,7 @@ import org.apache.hadoop.fs.permission.FsAction;
|
|||
import org.apache.hadoop.fs.permission.FsPermission;
|
||||
import org.apache.hadoop.security.AccessControlException;
|
||||
import org.apache.hadoop.security.SecurityUtil;
|
||||
import org.apache.hadoop.security.UserGroupInformation;
|
||||
import org.apache.hadoop.security.token.Token;
|
||||
import org.apache.hadoop.util.LambdaUtils;
|
||||
import org.apache.hadoop.util.Progressable;
|
||||
|
@ -456,8 +457,16 @@ public abstract class AbstractFileSystem {
|
|||
* @return current user's home directory.
|
||||
*/
|
||||
public Path getHomeDirectory() {
|
||||
return new Path("/user/"+System.getProperty("user.name")).makeQualified(
|
||||
getUri(), null);
|
||||
String username;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2241,8 +2241,16 @@ public abstract class FileSystem extends Configured
|
|||
* The default implementation returns {@code "/user/$USER/"}.
|
||||
*/
|
||||
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(
|
||||
new Path(USER_HOME_PREFIX + "/" + System.getProperty("user.name")));
|
||||
new Path(USER_HOME_PREFIX + "/" + username));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue